【发布时间】:2017-05-20 09:48:04
【问题描述】:
我想获取存储在 Html 源代码的 span 标签中的不同电影的 IMDB 评分。为此,我正在尝试使用 Html 解析从 HTML 跨度标签中收集数据。在调用返回 null 的 DocumentNode 的 SelectNodes() 方法之前,一切正常。
我知道这个问题之前已经被问过很多次了,但是尽管进行了大量研究并尝试了不同的解决方案,但我似乎无法弄清楚我的代码有什么问题。为了完成我的学期项目,解决这个问题对我来说真的很重要,所以任何形式的帮助都将不胜感激。 谢谢。
string url = "https://www.google.com/search?client=opera&q=into+the+wild&sourceid=opera&ie=UTF-8&oe=UTF-8";
StreamReader sourceCode = makeHttpRequest(url);
//makeRequest() returns the html source code of the url
String sourceCodeString = sourceCode.ReadToEnd();
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(sourceCodeString);
var itemList = doc.DocumentNode.SelectNodes("//span[@class='_tvg']")
.Select(p => p.InnerText)
.ToList();
【问题讨论】:
标签: c# html html-parsing html-agility-pack