jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 840
How would I adapt the following code please so I could get it into a XMLHTTP web pull instead? e.g.
Code:
Private Function getprices(ByVal URL As String) As Variant
Dim source As Object
Dim Http As New XMLHTTP60, Html As New HTMLDocument
Dim ret(1 To 1) As String
Dim elem As Object
With Http
.Open "GET", URL, False
.send
Html.body.innerHTML = .responseText
End With
Code:
Sub Getalllinks_tescos()
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
Dim cnt As Long: cnt = 1
Dim AR() As Variant: AR = Range("A1:A19").Value
Dim AL() As Variant
Dim url_name As String
IE.Visible = True
For i = LBound(AR) To UBound(AR)
url_name = AR(i, 1)
If url_name = "" Then Exit For
IE.navigate (url_name)
Do
DoEvents
Loop Until IE.ReadyState = 4
On Error Resume Next
Set AllHyperlinks = IE.Document.getElementsByClassName("product-list-container")(0).getElementsByTagName("A")
For Each hyper_link In AllHyperlinks
If InStr(hyper_link.href, "https://www.tesco.com/groceries/en-GB/products/") Then
ReDim Preserve AL(1 To cnt)
AL(cnt) = hyper_link.href
cnt = cnt + 1
End If
Next
Next i
IE.Quit
End Sub