Reading data from HTML source file
On this website: http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple I would like to get the value that represents the level "560".
I did some research and I figured out how to get all the source code with
string html = new WebClient().DownloadString(@"http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple");
and I think the value I should read is in the source code here:
(<span class="equipped">560</span> Equipped)
or here:
<div id="summary-averageilvl-best" class="best tip" data-id="averageilvl">
560
</div>
I tried to get this value using this method: qaru.site/questions/2156439 / ...
My code:
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;
However, ilvl is returned as null.
+3
source to share
3 answers
you can use regex (regex).
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
}
+2
source to share
you can use HTMLAgilityPack to parse HTML
HtmlDocument html = new HtmlDocument();
html.Load("http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple")
var myValue = html.DocumentNode.SelectNodes("//*[@class=\"equipped\"]");
+1
source to share