Scraping data from website using vba

eran3185

Board Regular
Joined
Apr 28, 2007
Messages
142
Hi

Im trying to Scrape data from website using vba.
i dont know how to get the element: data-position-num="2" in this html:

<a title="Google Docs Resume, Google Docs Resume Template Professional, Creative Google Docs Resume Template, Professional Resume Template Google Docs" class="prolist display-inline-block listing-link
logged" aria-label="Google Docs Resume, Google Docs Resume Template Professional, Creative Google Docs Resume Template, Professional Resume Template Google Docs (This link opens in a new tab or window)" href="https://www.etsy.com/listing/602716445/google-docs-resume-google-docs-resume?ga_order=most_relevant&ga_search_type=all&ga_view_type=gallery&ga_search_query=google sheets&ref=sc_gallery-1-2&plkey=48ceee7a476c685ca183c43d99a706ddf2a08a63:602716445" target="_blank" data-listing-id="602716445" data-behat-search-ad-link="" data-logging-key="48ceee7a476c685ca183c43d99a706ddf2a08a63:602716445" data-position-num="2" data-page-num="1" data-display-loc="w.0" data-palette-listing-image="">
_</a>

the url is : https://www.etsy.com/search?q=google+sheets&ref=pagination&page=1

Tnx
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
The elements with attribute data-position-num, all seem to be anchor (< a > tag) elements, though I haven't checked whether it also occurs in other tags. Therefore:

Code:
    For Each link In HTMLdoc.Links
        If link.getAttribute("data-position-num") = "2" Then
            Debug.Print link.href
        End If
    Next
where HTMLdoc is IE.Document with the page loaded.
 
Upvote 0
TNX.
But its not work :(

I try this code:

Sub hh()

Dim HTMLdoc As New InternetExplorer
HTMLdoc.navigate "https://www.etsy.com/search?q=google+sheets&explicit=1&order=most_relevant&ref=pagination&page=1"
HTMLdoc.Visible = True



For Each Link In HTMLdoc.Links
If Link.getAttribute("data-position-num") = "2" Then
Debug.Print Link.href
End If
Next

End Sub

Another question: Is there a way to get all the elements (not only "2") ?

Tnx again
 
Upvote 0
Try this. You must set references to MS Internet Controls and HTML Object Library.

Code:
Public Sub IE_Loop_Elements()

    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim link As HTMLAnchorElement
        
    Set IE = New InternetExplorer
    With IE
        .navigate "https://www.etsy.com/search?q=google+sheets&ref=pagination&page=1"
        .Visible = True
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With

    For Each link In HTMLdoc.Links
        If link.hasAttribute("data-position-num") Then
            Debug.Print link.href
        End If
    Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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