4

In this website : http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple I want to get the value that says "560" item level.

I've done some research and I figured out how to get all source code with

string html = new WebClient().DownloadString(@"http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple");

and i think the value which i should read is here in the source code :

(<span class="equipped">560</span> Equipped)

or here :

<div id="summary-averageilvl-best" class="best tip" data-id="averageilvl">
        560
    </div>

I have tried getting that value by using this way : https://stackoverflow.com/a/2958449/3935085

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 returns as null.

Community
  • 1
  • 1
Arefi Clayton
  • 841
  • 2
  • 10
  • 19

3 Answers3

2

you can use regular expression(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

}
worldofjr
  • 3,868
  • 8
  • 37
  • 49
blyt3stan
  • 44
  • 5
  • Hey thanks for you help. Your code fixed my problem and it is easy to understand. However, i am not really sure why did you type "([0-9]+)" in 'Regex.Match' parameters. – Arefi Clayton Aug 13 '14 at 00:07
  • im thinking that the value "560" might be dynamic(changing).. "([0-9]+)" is regular expression for numeric value – blyt3stan Aug 13 '14 at 00:10
  • http://stackoverflow.com/a/1732454/384478, give HtmlAgilityPack or SGMLReader a try instead. – Ilya Kozhevnikov Aug 13 '14 at 00:37
2

you can use HTMLAgilityPack to parse the HTML

HtmlDocument html = new HtmlDocument();
html.Load("http://eu.battle.net/wow/en/character/Kazzak/Ierina/simple")
var myValue = html.DocumentNode.SelectNodes("//*[@class=\"equipped\"]");
Kristian Damian
  • 1,360
  • 3
  • 22
  • 43
1

First Thing: you have a span with the CLASS "equipped" you are trying to get an element with the ID "equipped"

Second Thing: You could try to use a regular expression

LostPhysx
  • 3,573
  • 8
  • 43
  • 73