Scraping from Javascript rendered web page

fredrerik84

Active Member
Joined
Feb 26, 2017
Messages
383
Hi mr excel comunity :) I wonder if anyone know how to handle pages that are generated from javascript.

here is my basic code web scraper code:

Code:
Sub Somesite()


Dim XMLReq As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLRows As MSHTML.IHTMLElementCollection
Dim URL As String
Dim i As Long, j As Long


URL = "http://www.somesite.com"
    
    With XMLReq
        .Open "GET", URL, False
        .send
        Do While .readyState <> 4
            DoEvents
        Loop
    End With
    
    If XMLReq.Status <> 200 Then
        MsgBox "Error " & XMLReq.Status & ":  " & XMLReq.statusText
        Exit Sub
    End If
    
    HTMLDoc.body.innerHTML = XMLReq.responseText
    Set HTMLRows = HTMLDoc.getElementsByTagName("")
    
    
       j = 31
       For i = 0 To HTMLRows.Length - 1
          On Error Resume Next
          Cells(j, "Q").Value = HTMLRows(i).innerText
          j = j + 1
       Next i




End Sub

This basic code works for the sites ive testet that doesnt include javascript. But when I try to scrape from a site that uses javascript to generete its content all of this is not loaded into the html doc.

Does anyone know how to get this content using XMLReq., ?

best regards

frederik
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top