Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi folks
i have webBrowser1 control on my form
navigating website.
and that website looks like this
 
<html>
<body>
<div class="main">
dont interested this div tag
</div>
<div class="thin">
<a href="http://domain.ge/?showuser=116350">tbiliso_city</a>,
<a href="http://domain.ge/?showuser=56467">GIZ-888</a>,
<a href="http://domain.ge/?showuser=135926">t-90</a>,
</div>
</body>
<html>
 
http://domain.ge/?showuser=116350 is profile page link and "tbiliso_city" is username;
i want to read all of these links (or usernames) in div tag "thin" and put them in listbox Smile | :)
can u help me?
 
its my work but does not work
HtmlDocument doc = webBrowser1.Document;
            HtmlElementCollection col = doc.GetElementsByTagName("thin");
 
            foreach (HtmlElement element in col)
            {
                string cls = element.GetAttribute("href");
 
                HtmlElementCollection childDivs = element.Children.GetElementsByName("thin");
                foreach (HtmlElement childElement in childDivs)
                {
                  listBox1.Items.Add(childElement);
                }
Posted 20-Oct-11 10:04am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First thing which caught my eye is: <div class="thin"> does not define the name of the div element, it defines its CSS style class. Instead, use the attribute name (or both), for example: <div class="thin" name="thin">.
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The function "GetElementsByTagName" will get elements by tag name, not by class or ID. You happen to be looking for elements with the tag name "div", so that's what you'd want to pass to that function. You'd then want to check the "class" attribute (you already know how to do that, based on what I see in your code) to see if it equals "thin".
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

thanks i did
thats solution:
 
HtmlElementCollection a = webBrowser1.Document.GetElementsByTagName("a");
            foreach (HtmlElement b in a)
            {
                if (b.GetAttribute("href").StartsWith("http://forum.ge/?showuser="))
                {
                    string item = b.GetAttribute("href");
                    int indx = item.Length - 26;
                    string retString = item.Substring(26, indx);
                    listBox1.Items.Add(retString);
                    item = null;
                    retString = null;
                }
            }
  Permalink  
Comments
boom12345 at 9-Oct-12 7:01am
   
HtmlElementCollection a = webBrowser1.Document.GetElementsByTagName("a");i have a error to use a new keyword to create an instance of object...reply plz
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

boom12345
so try this:
HtmlElementCollection a = new HtmlElementCollection();
a = webBrowser1.Document.GetElementsByTagName("a");
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 565
1 Maciej Los 319
2 Richard MacCutchan 220
3 BillWoodruff 164
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100