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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

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