+ Reply to Thread
Results 1 to 9 of 9

Having trouble scraping data from IE

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    5

    Having trouble scraping data from IE

    This is driving me nuts. Pretty new to VBA. Here is the HTML:

    <script type="text/javascript">...</script>
    <div id="b_contant">
    <div id="b_tween">...</div>
    <OL ID="B_RESULTS">
    <LI CLASS="b_ans" data-bm="6">
    <h2>...</h2>
    <cite>bing.com/maps</cite>
    <div class="b_rich">
    <div class="b_imagepair square_xxxb reverse">
    <div class="inner"....</div>
    <div class="b_vpanel">...</div>
    <div class="b_panel">
    <div>
    <div class="b_focusTextSmall">1361.5 mi</div>

    I'm trying to get the 1361.5 mi.

    I've tried:
    Set alltags = IE.Document.getElementsByTagName("div")
    For Each element In alltags
        If element.getAttribute("class") = "b_focusTextSmall" Then
            mileagestring = element.innerText
            selectedtext() = Split(mileagestring, " ")
            miles = selectedtext(0)
    end if
    next
    It finds ~152 div but never finds a class of "b_focusTextSmall".

    What am I missing?
    Last edited by fabolous15; 02-21-2015 at 12:09 PM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Having trouble scraping data from IE

    fabolous15

    Welcome to the forum!
    Please use code tags with your code as per forum's 3 rule.
    You need a class

    If element.classname = "b_focusTextSmall" Then

  3. #3
    Registered User
    Join Date
    02-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    5

    Re: Having trouble scraping data from IE

    I'm not sure what that means. I've used similar code before but this time it never finds the class I've specified.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Having trouble scraping data from IE

    It means it finds what you are after. I saved the text on my folder and returns the text
    mileagestring = element.innertext

  5. #5
    Registered User
    Join Date
    02-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    5

    Re: Having trouble scraping data from IE

    Oh sorry, I was surfing on mobile and didn't see the code you posted.

    I tried that:
    Set alltags = IE.Document.getElementsByTagName("div")
    For Each element In alltags
        If element.className = "b_focusTextSmall" Then
            mileagestring = element.innerText
            selectedtext() = Split(mileagestring, " ")
            miles = selectedtext(0)
        End If
    Next
    and it still isn't finding classname "b_focusTextSmall". I also tried:
    Set alltags = IE.Document.all
    just to make sure and no dice.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Having trouble scraping data from IE

    Does the code loops through the class element? It should return nothing until it reaches the last loop 8.
    Please post the entire code including the URL
    Last edited by AB33; 02-21-2015 at 04:40 PM.

  7. #7
    Registered User
    Join Date
    02-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    5

    Re: Having trouble scraping data from IE

    Yeah but never meets the if criteria. I put a message box in to see if it ever made it inside the if

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Having trouble scraping data from IE



    Any URL link ?!

  9. #9
    Registered User
    Join Date
    02-20-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    5

    Re: Having trouble scraping data from IE

    Yeah here's a link. I changed the addresses so the mileage will be different.

    http://www.bing.com/search?q=miles%2...f580d17fd489d4

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Scraping Data from Web Into Excel Using VBA
    By gurs in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-31-2015, 06:26 PM
  2. Scraping data and pre-processing in one go?
    By xteejx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2014, 02:41 PM
  3. scraping data from a website
    By redpanda in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-05-2012, 01:20 PM
  4. Scraping Data using VBA
    By Nala2355 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2011, 11:21 AM
  5. Data scraping
    By brewers7 in forum Excel General
    Replies: 8
    Last Post: 02-06-2011, 12:45 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1