【发布时间】:2012-07-18 11:43:19
【问题描述】:
我正在使用 Html Agility Pack 来获取页面上每个产品的信息:
我的代码是这样,但节点返回 null。我正在使用通过 Google Chrome 找到的 Xpath。
private void getDataBtn_Click(object sender, EventArgs e)
{
if (URL != null)
{
HttpWebRequest request;
HttpWebResponse response;
StreamReader sr;
List<string> Items = new List<string>(50);
HtmlAgilityPack.HtmlDocument Doc = new HtmlAgilityPack.HtmlDocument();
request = (HttpWebRequest)WebRequest.Create(URL);
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
Doc.Load(sr);
var Name = Doc.DocumentNode.SelectSingleNode("/html/body/table[2]/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[3]/a");
}
}
我做错了什么?有没有其他工具可以创建兼容敏捷包的 xpath 表达式?
【问题讨论】:
-
我明白你的意思...问题是网页会动态加载一些内容。当您尝试获取未加载动态内容的页面时,这就是您获得空值的原因..请参阅我的问题..有同样的问题。 stackoverflow.com/questions/18955793/…
标签: c# html parsing xpath html-agility-pack