HTMLAgilityPack 获取 AJAX 值
我正在尝试使用 HtmlAgilityPack 获取计时器的值,但是当我通过元素 ID 获取 innerText 时,它返回 --:--:--
有没有办法获取时间值,因为它使用 AJAX?
I am trying to get the value of a timer using the HtmlAgilityPack however when I get the innerText by the element ID it returns --:--:--
Is there any way to get the time value since it uses AJAX?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,当您加载 HttpAgilityPack.HtmlDocument(当然是从网络)时,它会向网站发出 HTTP Web 请求,而您收到的是纯文本。未加载 AJAX/JavaScript 或图像。当您在浏览器中看到它时,您不会意识到它,因为它是一个浏览器;)。收到响应后,它开始加载图像、动画并执行 javascript 代码,但
HtmlAgilityPack
使用HttpWebRequest
来获取源代码,并且它不管理任何 javascript 代码。我建议您下载一个非常出色的工具来检查网络中的 HTTP 流量:Fiddler2。它将允许您设置断点,并准确查看响应是如何返回的,您将看到这些事情实际上是由浏览器本身处理的。
我真的不知道在 AJAX 中获取计时器的时间值的目的是什么,但我认为你可以使用 WaTiN 使用 Internet Explorer 加载源(并隐藏它,因为如果没有,加载页面的屏幕上会出现 IE 窗口),在需要获取计时器值的时刻,获取源来自 WaTiN 并使用
LoadHtml(string html)
加载HtmlDocument
。The thing is that when you load an
HttpAgilityPack.HtmlDocument
(from the web, of course), it makes an HTTP web request to the website, and what you receive is plain text. No AJAX/JavaScript or images are loaded. When you see it in a browser, you don't realize about it, because it's a browser ;). After it receives the response, it starts loading images, animations, and executing javascript code, butHtmlAgilityPack
usesHttpWebRequest
to get the source, and it doesn't manage any javascript code.I suggest you to download a really brilliant tool to inspect HTTP traffic in your network: Fiddler2. It will allow you to set breakpoints, and see exactly how the response is returned, and you will see that those things are really handled by the browser itself.
I don't really know what is the purpose of getting the time value of a timer in AJAX, but I think you could use WaTiN to load the source using Internet Explorer (and hidding it, because if not, an IE window will appear on the screen loading the page), and in the moment you need to get the value of the timer, get the source from WaTiN and load an
HtmlDocument
usingLoadHtml(string html)
.