• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Applying ID to get web data Using VBA

shahin

Active Member
Hi there! Hope you all are doing well. So far when I worked with vba to fetch web data I used either "class" or "tag" name to parse that. But, in case of applying "ID" I got stuck. Using class name I can get the data from this site but when I trend to apply "ID" to get the same it throws error. Perhaps I'm doing something wrong which I can't identify. Hope somebody out there will help me to accomplish this. Thanks in advance.

Code:
Sub FashionStuff()
Dim http As New MSXML2.XMLHTTP60, html As New HTMLDocument
Dim elements As Object, element As Object, post As Object

With http
    .Open "GET", "https://www.sephora.ae/en/stores/", False
    .send
    html.body.innerHTML = .responseText
End With

Set elements = html.getElementById("mm-makeup-nav-item")
Set element = elements.getElementsByTagName("a")

    For Each post In element
        x = x + 1
        Cells(x, 1) = post.href
    Next post
    Set http = Nothing: Set elements = Nothing: Set element = Nothing
End Sub
 
Thanks sir for the link. I've got it solved with another site.
Code:
Sub TorrentData()
Dim http As New MSXML2.ServerXMLHTTP, html As New HTMLDocument
Dim topics As Object, topic As Object, post as object

With http
    .Open "GET", "https://www.yify-torrent.org/search/1080p/", False
    .send
    html.body.innerHTML = .responseText
End With

Set topics = html.getElementById("main")
Set topic = topics.getElementsByTagName("img")

    For Each post In topic
        x = x + 1
        Cells(x, 1) = post.src
    Next post
Set html = Nothing: Set topics = Nothing: Set topic = Nothing
End Sub
 
OR
Code:
Sub TorrentData()
Dim http As New MSXML2.ServerXMLHTTP, html As New HTMLDocument
Dim topics As Object, post As Object

With http
    .Open "GET", "https://www.yify-torrent.org/search/1080p/", False
    .send
    html.body.innerHTML = .responseText
End With

Set topics = html.getElementById("main").getElementsByTagName("img")

    For Each post In topics
        x = x + 1
        Cells(x, 1) = post.src
    Next post
Set html = Nothing: Set topics = Nothing
End Sub
 
Back
Top