XPath查询问题使用HTML敏捷性包 [英] XPath Query Problem using HTML Agility Pack

查看:151
本文介绍了XPath查询问题使用HTML敏捷性包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图刮去本网站。使用HTML敏捷性包

I'm trying to scrape the price field from this website using the HTML Agility Pack.

我的代码如下:

var web = new HtmlWeb();
var doc = web.Load(String.Format(overClockersURL, componentID));
var priceContent = doc.DocumentNode.SelectSingleNode("//*[@id=\"prodprice\"]");



我用Firebug的获得XPath查询复制为XPath的功能

我遇到的问题是,的SelectSingleNode 将返回的无效 - 它似乎并没有找到由查询指定的元素。我有点难倒,为什么,但我没有使用XPath太多的经验,所以希望得到一些指针为我做了什么错。

The problem I'm having is that SelectSingleNode is returning null - it doesn't seem to find the element specified by the query. I'm a bit stumped as to why, but I don't have much experience with XPath, so would appreciate some pointers as to what I've done wrong.

推荐答案

当发生这种情况,你应该检查,如果页面被正确加载(你说你是通过HTTP代理服务器?)

When that happens, you should check if the page is being loaded correctly (you said you're through a HTTP Proxy?)

尝试 doc.DocumentNode.OuterHtml 的内容写入到一个文本文件,所以你可以看到,如果页面被正确加载。也许你得到一个错误页面,而不是原来的页面。

Try writing the content of doc.DocumentNode.OuterHtml to a text file so you can see if the page is being loaded correctly. Maybe you're getting an error page instead of the original page.

这篇关于XPath查询问题使用HTML敏捷性包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆