Scrape html table for multiple web urls

pradeepvvce

New Member
Joined
Mar 20, 2018
Messages
1
Please find the below code for 1 url. How to scrape data for multiple urls that is pasted in sheet 1 of excel and result of the scraped data in sheet 2.

Sub Test()
Dim html As Object
Dim tbl As Object
Dim tRow As Object
Dim tCel As Object
Dim X As Long
Dim y As Long

With CreateObject("MSxml2.XMLHTTP")
.Open "GET", "https://www.cesco.com/Eaton-Cooper-Lighting-SHK-Cooper-Lighting-SHK-Fixture-Hook-With-2-1-2-Inch-Safety-Screw-Die-Cast-Aluminum/p2085509", False
.send
Set html = CreateObject("htmlfile")
html.body.innerHTML = .responseText
End With

For Each tbl In html.getElementsByTagName("table")
For Each tRow In tbl.getElementsByTagName("tr")
For Each tCel In tRow.getElementsByTagName("td")
y = y + 1
If y = 2 Or y = 4 Then
Cells(X + 1, IIf(y = 2, 1, 2)) = tCel.innerText
End If
Next tCel
y = 0
X = X + 1
Next tRow
Next tbl
End Sub
Sub Test()
Dim html As Object
Dim tbl As Object
Dim tRow As Object
Dim tCel As Object
Dim X As Long
Dim y As Long

With CreateObject("MSxml2.XMLHTTP")
.Open "GET", "https://www.cesco.com/Eaton-Cooper-Lighting-SHK-Cooper-Lighting-SHK-Fixture-Hook-With-2-1-2-Inch-Safety-Screw-Die-Cast-Aluminum/p2085509", False
.send
Set html = CreateObject("htmlfile")
html.body.innerHTML = .responseText
End With

For Each tbl In html.getElementsByTagName("table")
For Each tRow In tbl.getElementsByTagName("tr")
For Each tCel In tRow.getElementsByTagName("td")
y = y + 1
If y = 2 Or y = 4 Then
Cells(X + 1, IIf(y = 2, 1, 2)) = tCel.innerText
End If
Next tCel
y = 0
X = X + 1
Next tRow
Next tbl
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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