[英]Reading data from HTML source file
在这个网站: http : //eu.battle.net/wow/en/character/Kazzak/Ierina/simple我想得到“560”项目级别的值。
我做了一些研究,并想出了如何获取所有源代码
string html = new WebClient().DownloadString(@"http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple");
我认为我应该阅读的价值在源代码中:
(<span class="equipped">560</span> Equipped)
或者在这里:
<div id="summary-averageilvl-best" class="best tip" data-id="averageilvl">
560
</div>
我尝试使用这种方式获得该值: https : //stackoverflow.com/a/2958449/3935085
我的代码:
webBrowser1.DocumentText = new WebClient().DownloadString(@"http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple");
HtmlElement ilvl = webBrowser1.Document.GetElementById("equipped");
label1.Text = ilvl.InnerText;
但是,ilvl返回null。
你可以使用正则表达式(正则表达式)。
string input = new WebClient().DownloadString(@"http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple");
// Here we call Regex.Match for <span class="equipped">560</span>
Match match = Regex.Match(input, @"<span class=\""equipped\"">([0-9]+)</span>",
RegexOptions.IgnoreCase);
// Here we check the Match instance.
if (match.Success)
{
string key = match.Groups[1].Value; //result here
}
您可以使用HTMLAgilityPack来解析HTML
HtmlDocument html = new HtmlDocument();
html.Load("http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple")
var myValue = html.DocumentNode.SelectNodes("//*[@class=\"equipped\"]");
第一件事:你有一个CLASS "equipped"
的跨度,你试图获得一个ID为 "equipped"
的元素
第二件事:您可以尝试使用正则表达式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.