【发布时间】:2011-11-30 22:49:12
【问题描述】:
谁能告诉我使用 HTMLAgilityPack 获取内容的最佳方法,我在下面提到的 html 中。
在提供的 HTML 中,我需要抓取 ID“img”的 value 并设置 x 和 y 的值,以便它们在另一个函数中使用。
相关的HTML是
<div id="values">
<input type="hidden" id="x" name="x" value='0' />
<input type="hidden" id="y" name="y" value='0' />
<input type="hidden" id="img" name="img" value="86932" />
<input type="hidden" id="source" name = "source" value="center" />
这些值被发送到下面显示的 javascript 中的函数
submitClick(document.getElementById("img").getAttribute("value"),
document.getElementById("x").getAttribute("value"),
document.getElementById("y").getAttribute("value"),
'tiled' );
有人可以告诉我应该如何进行吗...
我已经编写了以下代码来获取页面的 html 数据
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "GET";
using (var stream = request.GetResponse().GetResponseStream())
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(new StringReader(result));
HtmlNode root = doc.DocumentNode;
现在我已经有了根,我应该如何搜索参数然后通过 GET 发送它们。
【问题讨论】:
标签: c# ajax web-scraping html-agility-pack