当使用HAP解析html文档时,我遇到了使用图片的src属性的问题。 ID src属性值是一个长的URL与参数,例如:<img border='0' title='Kommunelogo' alt='Kommunelogo' style='margin-top: 5px;' src='http://livskraftig.bedrekommune.no/more/reports/profilechart.jsp?legend=Y&graphtype=xy&profileid=19433213274429306&element=72&addyears=true' />
HTML敏捷包使用src属性解析图片的长链接
那么HAP解析图像是这样的:<img border='0' title='Kommunelogo' alt='Kommunelogo' style='margin-top: 5px;' src='http://livskraftig.bedrekommune.no/more/reports/profilechart.jsp?legend="Y"&amp;graphtype="xy"&amp;profileid="19433213274429306"&amp;element="72"&amp;addyears="tru"e'/>
它看起来像HAP拆分PARAMS以为他们都是属性。
我的代码:
HtmlDocument doc = new HtmlDocument();
doc.OptionOutputAsXml = true;
doc.OptionAutoCloseOnEnd = true;
doc.OptionFixNestedTags = true;
doc.LoadHtml(input_which_is_a_whole_html_file);
HtmlAgilityPack.HtmlNodeCollection imageNodes = doc.DocumentNode.SelectNodes("//img");
if (imageNodes != null)
{
foreach (HtmlAgilityPack.HtmlNode imgNode in imageNodes)
{
string imgSrc = imgNode.Attributes["src"].Value;
}
}
任何想法如何避免这种情况?
非常感谢!
您能否向我们提供您想要解析的整个文档?在仅使用'img'的文档中测试代码,HAP可以完美地返回网址。 – 2010-12-04 08:49:03