【发布时间】:2016-10-20 04:37:51
【问题描述】:
我尝试使用 htmlagilitypack 解析表格,完成后我意识到我忘记证明 htmlagility 部分是否有效。 ... 很明显它不起作用 我也不知道我错过了什么,我在哪里做错了…… 因为我是初学者... 所以请不要对我太苛刻。
public partial class WebForm1 : System.Net.Http.HttpClient
{
protected void Page_Load(object sender, EventArgs e)
{
System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
string header = "ie";
if (!headers.UserAgent.TryParseAdd(header))
{
throw new Exception("Invalid header value: " + header);
}
header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
if (!headers.UserAgent.TryParseAdd(header))
{
throw new Exception("Invalid header value: " + header);
}
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(" http://www.eurogymnasium-waldenburg.de/egw_content/Stunden_Vertretungsplan/home.html");
HtmlNode docNodes = htmlDoc.DocumentNode;
HtmlNode navNode = htmlDoc.GetElementbyId("bereichaktionen");
HtmlNode docNode = htmlDoc.DocumentNode.SelectSingleNode("/html/body[@class='ui-widget']/div[@id='main']/div[@id='vplan']/div[@id='bereichaktionen']");
string nodeValue;
nodeValue = (docNode.InnerText);
Debug.WriteLine("nodeValue");
//我怀疑上面有什么问题,但我不确定是什么问题。
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
{
}
else
{
if (htmlDoc.DocumentNode != null)
{
HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
if (bodyNode != null)
{
}
}
}
}
源地址在那里,你们可以试试
谢谢大家 X.L
【问题讨论】:
标签: c# html win-universal-app uwp html-agility-pack