By: Alok Paul

In reply to Dennis Ryan.

Hi Dennis Ryan,
Thank you very much for reading our articles. You mentioned that you have modified the code to get texts. But you want to get URLs by Web Scraping with Chrome. You can try the following VBA code for that.

VBA Macro:

Sub scraping_web_urls()
Dim chrm As New ChromeDriver
Dim objLinks As Object
Dim objLink As Object
Dim iRow As Long
chrm.Get “/excel-vba-translate-formula-language/”
chrm.Wait 4000
Set objLinks = chrm.FindElementsByTag(“a”)
iRow = 3
For Each objLink In objLinks
ActiveSheet.Cells(iRow, 2).Value = objLink.Attribute(“href”)
iRow = iRow + 1
Next objLink
chrm.Quit
End Sub

Code Breakdown

Dim chrm As New ChromeDriver, Dim objLinks As Object, Dim objLink As Object, Dim iRow As Long
1st we declared different variables with type.

chrm.Get “/excel-vba-translate-formula-language/”
Navigate to a specific web link.

chrm.Wait 4000
Waits for 4000 milliseconds or 40 seconds.

Set objLinks = chrm.FindElementsByTag(“a”)
Sets the value of the objLinks variable.

iRow = 3
Set the value of iRow to 3.

For Each objLink In objLinks
ActiveSheet.Cells(iRow, 2).Value = objLink.Attribute(“href”)

Find each objLink from objLinks. And paste them in the second column of row 3. Here, href is used for getting hyperlinks.

iRow = iRow + 1
Increase the value of iRow to move to the next row.

chrm.Quit
This tells the ChromeDriver to quit Google Chrome.

Look at the output. This will extract all the URLs that exist in the given link.

More URLs are present in this sheet.