VBA - HOW TO: SCRAPE ALL LINKS FROM WEBSITE

Опубликовано: 12 Май 2026
на канале: E Doherty
2,025
9

Yeah, So long story short. Grab the HTML Doc from the URL and grab the HREF's... Should be fun!

TOOLS -- REF ---Microsoft HTML

Sub test()

Dim Html As HTMLDocument

Dim collection As MSHTML.IHTMLElementCollection
Dim element As MSHTML.HTMLInputElement, subElement As MSHTML.HTMLInputElement

URL = "https://news.google.com/news"

Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "GET", URL, False
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.send

Set Html = CreateObject("htmlfile")
Html.body.innerHTML = xmlHttp.responseText

Set collection = Html.getElementsByTagName("a")

For Each element In collection
Debug.Print element.href
Next


MsgBox ("Done")
End Sub