Get the value of all td tags using xpath and html agilty

c# html-agility-pack web-scraping xpath

Question

How can I get information out of all td tags in Classen = "string_14" so that I can store it away clean without html code in.

I have thought about this:

enter code here
<table class="string_14">
                <tbody><tr>
                    <td>Postadr.:</td> 
                    <td class="tab_space">Stenslivegen 67, 2817 Gjøvik</td> 
                </tr>
                <tr>
                    <td>Telefon:</td> 
                    <td class="tab_space">611 80 710</td>
                </tr>

                <tr>
                    <td>Mobil:</td> 
                    <td class="tab_space">957 92 455</td>
                </tr>
                </tbody>
                </table>

And my code to get it looking like this today, I want help with is to write xpath to name =? how should I write to get a single td.

        HtmlDocument doc = new HtmlDocument();
        doc.Load(new StringReader(result));
        HtmlNode root = doc.DocumentNode;


        List<string> list = new List<string>();
        foreach (HtmlNode div in root.SelectNodes("//div[@class='biz_list']"))
        {
            string name = doc.DocumentNode.SelectNodes("//d[@class='string_14']/@tr");
            list.Add(name);
            string att = div.OuterHtml;
            list.Add(att);
        }

What I want out of this is I'm going to scrape a page and then the LATE stage I'll save this down to the xml file.

Popular Answer

I think what you want is this:

HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("//table[@class='string_14']//td[@class='tab_space']");

You can consult XPath Tutorial for more on this.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why