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.

4
  • GetElementById() will only retrieve elements by ID (not class name). This may help: stackoverflow.com/a/8461952/453277 Commented Aug 12, 2014 at 23:14
  • If you are retrieving it by an ID then use the second div ID you posted summary-averageilvl-best. Commented Aug 12, 2014 at 23:23
  • 1
    I have also noticed that my webBrowser1.DocumentText returns as "HTML></HTML>\0" would it be my problem ? Commented Aug 12, 2014 at 23:31
  • Thank you all for your comments. Commented Aug 13, 2014 at 0:07

3 Answers 3

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

}
Sign up to request clarification or add additional context in comments.

3 Comments

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.
im thinking that the value "560" might be dynamic(changing).. "([0-9]+)" is regular expression for numeric value
stackoverflow.com/a/1732454/384478, give HtmlAgilityPack or SGMLReader a try instead.
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\"]");

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.