Results 1 to 2 of 2

Thread: Convert code for HTML Agility Pack

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    Convert code for HTML Agility Pack

    I posted my original code that I wrote using a webbrowser. I was having problems with memory leakage build up after navigating to over a hundred webpages so I'm rewriting the code using HTML Agility Pack. I'm not sure how to implement a If span_tag.GetAttribute("classname") = "olpShippingPrice" Then statement for HTML Agility Pack. How do you do a boolean attribute comparison in HTML Agility Pack?


    Original code
    **************
    If div_tag.GetAttribute("classname") = "a-row a-spacing-mini olpOffer" Then
    Dim span_tags As HtmlElementCollection = div_tag.GetElementsByTagName("span")
    Dim total_price As Double = 0
    For Each span_tag As HtmlElement In span_tags
    If span_tag.GetAttribute("classname") = "a-size-large a-color-price olpOfferPrice a-text-bold" Then
    select_datagridview.Item(10, i).Value = select_datagridview.Item(10, i).Value & " | " & span_tag.InnerText
    select_datagridview.Item(11, i).Value = select_datagridview.Item(11, i).Value & " | " & span_tag.InnerText
    total_price = utility_library_1.convert_string_to_double(utility_library_1.regex_scrapper("\d+(\.\d+)?", span_tag.InnerText))
    End If
    If span_tag.GetAttribute("classname") = "olpShippingPrice" Then
    total_price = total_price + utility_library_1.convert_string_to_double(utility_library_1.regex_scrapper("\d+(\.\d+)?", span_tag.InnerText))
    select_datagridview.Item(10, i).Value = select_datagridview.Item(10, i).Value & "+" & span_tag.InnerText & " (" & _
    total_price & ")"
    select_datagridview.Item(11, i).Value = select_datagridview.Item(11, i).Value & "+" & span_tag.InnerText & " (" & _
    total_price & ")"
    End If
    Next

    **************************
    Converted code for HTML Agility Pack - not completed.
    **************************
    Dim htmlDoc As New HtmlDocument
    htmlDoc.LoadHtml(website_download)

    For Each price_div_tag As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//div[@class='a-row a-spacing-mini olpOffer']")
    For Each price_span_tag As HtmlNode In price_div_tag.SelectNodes("//span[@class='a-size-large a-color-price olpOfferPrice a-text-bold']")
    Dim total_price As Double = 0
    select_datagridview.Item(10, i).Value = select_datagridview.Item(10, i).Value & " | " & utility_library_1.regex_scrapper("\d+(\.\d+)?", price_span_tag.InnerText)
    select_datagridview.Item(11, i).Value = select_datagridview.Item(11, i).Value & " | " & utility_library_1.regex_scrapper("\d+(\.\d+)?", price_span_tag.InnerText)
    total_price = utility_library_1.convert_string_to_double(utility_library_1.regex_scrapper("\d+(\.\d+)?", price_span_tag.InnerText))
    Next

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Convert code for HTML Agility Pack

    Please use appropriate formatting tags when posting code snippets.

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
  •  



Click Here to Expand Forum to Full Width