IE.Document.getElementsByTagName("A")

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
834
So I have some code which pulls URLs from URLs by tagname if it contains the If Instr in the code below.

I'd like this to focus just on one section of the webpage, Div Class:

Div Class: product-list-container

and exclude:

Div Class: recommender__wrapper

The code is as follows:

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:A3").Value
Dim AL() As Variant
Dim url_name As String
Dim LR As Long


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


    Set AllHyperlinks = IE.Document.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


Range("B1").Resize(UBound(AL), 1).Value = Application.Transpose(AL)


End Sub

Many thanks in advance.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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