Results 1 to 5 of 5

Thread: scrape the string between the div tag

  1. #1
    Addicted Member
    Join Date
    Aug 11
    Posts
    156

    scrape the string between the div tag

    How do I scrape the string between the div tag? td_tag.InnerText is empty. There are no attributes.

    *************
    Dim td_tags As HtmlElementCollection = wb.Document.GetElementsByTagName("td")
    For Each td_tag As HtmlElement In td_tags
    If td_tag.GetAttribute("classname") = "bids bin1" Then
    TextBox11.Text = TextBox11.Text & " - " & td_tag.InnerText
    End If
    Next

    **********************
    <td class="bids bin1">
    <div>Buy It Now</div>
    </td>

  2. #2
    Addicted Member
    Join Date
    Aug 11
    Posts
    156

    Re: scrape the string between the div tag

    Anyone knows how to scrape this string?

  3. #3
    Hyperactive Member
    Join Date
    Jul 11
    Location
    UK
    Posts
    438

    Re: scrape the string between the div tag

    I would use just one WebBrowser Control, go back to your original code and fix the bug in it. The outline of your code might look like:
    vb.net Code:
    1. '  Collection of Rows
    2. Dim trs As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("tr")
    3.  
    4. For Each tr As HtmlElement In trs
    5.     '  Filter on  itemprop="offers"
    6.     If tr.GetAttribute("itemprop") = "offers" Then
    7.  
    8.         '  Collection of Cells
    9.         Dim td_tags As HtmlElementCollection = tr.GetElementsByTagName("td")
    10.  
    11.         For Each td_tag As HtmlElement In td_tags
    12.  
    13.            '  pull required data from elements of each pertinent cell
    14.            '
    15.            '  e.g.
    16.            'If td_tag.GetAttribute("classname").Contains("bids") Then
    17.            '    TextBox11.Text = TextBox11.Text & vbCrLf & " - " & td_tag.InnerText.Replace(vbCrLf, "")
    18.            'End If
    19.  
    20.         Next ' TD
    21.     End If ' filter
    22.  
    23. Next ' TR

    Note that for the bids cell, the class name changes by row, so you might want to use a part of the class name that is common to all rows, like "bids"

    Also note that the InnerText of this cell may contain a line break, so you may need to replace that with "".

  4. #4
    Lively Member Blupig's Avatar
    Join Date
    Apr 08
    Posts
    111

    Re: scrape the string between the div tag

    Could always use Regex or indices and subtrings, but it wouldn't be as flexible

  5. #5
    Addicted Member
    Join Date
    Aug 11
    Posts
    156

    Re: scrape the string between the div tag

    Inferrd, Thank you for all you assistance. Your last solution was right on.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •