+ Reply to Thread
Results 1 to 3 of 3

Pulling data from websites such as amazon using Excel VBA

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    hong kong
    MS-Off Ver
    Excel 2003
    Posts
    2

    Pulling data from websites such as amazon using Excel VBA

    Dear Excel Gurus,

    I am a newbie in Excel VBA and inspired by a video called Excel VBA Pull Data from A Website, I wonder if it's possible to apply this onto websites like amazon.com or barnesandnoble.com.

    So instead of typing in the zip code and getting the city and county, i get stuffs like the book title, author, ISBN, new price, used price, etc, by typing in the book name i am looking for.

    But for simplicity, lets start with the book title and price only. So now I have 2 columns and 3 rows.

    A1, A2, and A3 are labels
    B1 is the search field (lets call it search)
    B2 is the title (lets call it title)
    B3 is the price (lets call it price)

    Here's what I have so far:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = Range("search").Row And _
    Target.Column = Range("search").Column Then
    Dim IE As New InternetExplorer
    IE.Visible = False
    IE.navigate "www.amazon.com/s/?field-keywords=" & Range("search").Value
    Do
    DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    Dim Doc As HTMLDocument
    Set Doc = IE.document
    Dim sDD As String

    And I am stuck here. I used inspect element on the title of the first result and the #text is actually within several layers of DIVs, an H3, and an A. New Price is in STRIKE. And I have no idea how to tell VBA to look for layers of DIVs cause the one in the video (dd) is directly under BODY.

    Secondly, the video used the script:
    sDD = split(sDD,VbNewLine)(0)
    what does this mean. Do I have to use this in my case?

    Any ideas or suggestions are appreciated. I am just trying to do this to make my learning more interesting and applicable.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    04-24-2012
    Location
    hong kong
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Pulling data from websites such as amazon using Excel VBA

    Not working obviously but might as well post it for you guys to see what's wrong:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = Range("Search").Row And _
    Target.Column = Range("Search").Column Then
    Dim IE As New InternetExplorer
    IE.Visible = True
    IE.navigate "www.amazon.com/s/?field-keywords=" & Range("Search").Value
    Do
    DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    Dim Doc As HTMLDocument
    Set Doc = IE.document
    Dim sDD As String
    sDD = Trim(Doc.getElementsByTagName("DIV")(1).getElementsByTagName("DIV")(2).getElementsByTagName("DIV")(0).getElementsByTagName("DIV")(0).getElementsByTagName("DIV")(1).getElementsByTagName("DIV")(3).getElementsByTagName("DIV")(0).getElementsByTagName("DIV")(2).getElementsByTagName("H3")(0).getElementsByTagName("A")(0).innerText)
    MsgBox sDD
    End If
    End Sub

  3. #3
    Registered User
    Join Date
    03-31-2020
    Location
    Toccoa, GA
    MS-Off Ver
    app
    Posts
    1

    Re: Pulling data from websites such as amazon using Excel VBA

    Did you ever find a solution to the amazon thing?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1