Results 1 to 1 of 1

VBA code for scraping data from a URL - not pulling all data

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    VBA code for scraping data from a URL - not pulling all data

    Hi guys, below is the code I am currently using to pull data from a URL. It is pulling a value of one string however not the other one.

    I have attached the sample workbook below for your information.

    Any suggestions?

    Sub Sample_test()
    
        Dim IE As New InternetExplorer
        Dim sht As Worksheet
        Dim LastRow As Long
        Dim rCell As Range
        Dim rRng As Range
        Dim sUrl As String
        Dim ele As Object
        
        Dim icoid As String
        Dim des As String
        
        Set sht = ThisWorkbook.Worksheets("Sheet1")
        LastRow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row
        Set rRng = sht.Range("B3:B" & LastRow)
    
        For Each rCell In rRng.Cells
        sUrl = rCell.Value
    
        IE.navigate sUrl
    
        Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop
    
        For Each ele In IE.document.getElementsByClassName("tab-content")
            On Error Resume Next
            
            icoid = Trim(ele.Children(3).getElementsByClassName("col-md-6")(0).getElementsByTagName("table")(0).getElementsByTagName("tr")(0).getElementsByTagName("td")(0).innerText)
            des = Trim(ele.Children(2).getElementsByClassName("col-md-6")(0).getElementsByClassName("col-12")(0).getElementsByTagName("table")(0).getElementsByTagName("tr")(0).getElementsByTagName("td")(0).innerText)
    
            If Not Err Then
            rCell.Offset(0, 1).Value = icoid
            rCell.Offset(0, 2).Value = des
            End If
    
            On Error GoTo 0
    
        Next ele
        
        icoid = vbNullStrings
        des = vbNullString
    
        Next rCell
    
    Set IE = Nothing
    IE.Quit
        
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 02-17-2014, 11:21 PM
  2. vba help - code pulling incorrect date range from data set
    By vagelisgeo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2013, 02:12 PM
  3. Scraping website data when Get External Data from Web doesnt work
    By Zipping2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2013, 12:16 AM
  4. [SOLVED] Code to reference cell as parameter when pulling data
    By jaimealvarez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2012, 09:58 AM
  5. Code for passing a date as a parameter when pulling data
    By jaimealvarez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 11:52 AM
  6. Code to pulling specific data from a sheet
    By pnaquin in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-26-2011, 05:32 PM
  7. Issues with code pulling data consistently from spreadsheet
    By cummins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2011, 02:32 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