Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi folks
i have webBrowser1 control on my form
navigating website.
and that website looks like this

XML
<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 :)
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

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
 
Share this answer
 
v2
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".
 
Share this answer
 
thanks i did
thats solution:

C#
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;
                }
            }
 
Share this answer
 
Comments
boom12345 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
boom12345
so try this:
C#
HtmlElementCollection a = new HtmlElementCollection();
a = webBrowser1.Document.GetElementsByTagName("a");
 
Share this answer
 
Comments
Member 10371894 26-Feb-15 20:57pm    
i have a table defined in html page, where i need to get the data from table to list how can i do that..?

here is my design

<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="">
<tbody>
<tr>
<td align="left" valign="top" class="small">FIDELITY NATIONAL FINANCIAL, INC. <br>   (Y10070072898)</td>
<td align="right" valign="top"><img src="/images/hpweb_1-2_info_icn.gif" border="0" alt="detail for FIDELITY NATIONAL FINANCIAL, INC."></td>
</tr>
</tbody>
</table>

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900