0

I have created Macro which can read all the HTML of provided URL, however I want to fetch all the url from that HTML.

    Sub GetHTML_Click()

Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim j As Integer
Set ie = New InternetExplorer
ie.Visible = True

url = Cells(1, 2)

ie.navigate url

Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to website ..."
Loop
Application.StatusBar = " "
Set html = ie.document
'Dim htmltext As Collection
Dim htmltext As String
htmltext = html.DocumentElement.innerHTML
'Need to add iURL
Dim htmlurl As IHTMLElement
For Each htmlurl In hmtltext
iurl = htmlurl.toString
Cells(j, 1).Value = CLng(iurl)
j = j + 1
Next

End Sub

I tried to code this to fetch the URLs however its giving "Object Required error"

can anyone please help to modify this macro which will help me to fetch all the URL from HTML page.

I am using www.mini.in website for testing.

Mayur.

Mayur Alaspure
  • 69
  • 1
  • 2
  • 11

1 Answers1

0

Try this :

Dim ie As Object
Dim html As Object
Dim j As Integer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
URL = "google.com"
ie.Navigate URL
Do While ie.ReadyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to website ..."
Loop
Application.StatusBar = " "
Set html = ie.Document
'Dim htmltext As Collection
Dim htmlElements As Object
Dim htmlElement As Object
Set htmlElements = html.getElementsByTagName("*")
For Each htmlElement In htmlElements
    If htmlElement.getAttribute("href") <> "" Then Debug.Print htmlElement.getAttribute("href")
Next
winghei
  • 632
  • 4
  • 9