Scrapping Amazon website with VBA to get the prices of all the sellers

dorras

New Member
Joined
Sep 7, 2021
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am a beginner at VBA.
I am trying to retrieve the prices of all the sellers displayed on a product page on the Amazon website.
For now, I managed to create the below code which should open the web page and get the HTML code , but I get an error 462 "the remote server machine does not exist or is unavailable"
Could you please help me understanding why?

VBA Code:
Sub InternetExplorerObject()

Dim IEObject As InternetExplorer


Set IEObject = New InternetExplorer
IEObject.Visible = True
    
IEObject.Navigate URL:="https://www.amazon.fr/dp/B084CQ41M2/?psc=1", Flags:=navOpenInNewWindow
    
Do While IEObject.Busy = True Or IEObject.ReadyState <> READYSTATE_COMPLETE
       
Application.Wait Now + TimeValue("00:00:01")
       
Loop
   
Debug.Print IEObject.LocationURL
    
   
    Dim IEDocument As HTMLDocument
    Set IEDocument = IEObject.Document
    
    'The simplest thing we can do is grab an element, and then the inner text.
    Debug.Print IEDocument.getElementById("header").innerText
    
  End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hello,​
the error raises 'cause you are searching an Id which does not exist …​
 
Upvote 0
Webscraping is not very reliable, since the page will probably change now and then. When it does, you have to rewrite your code.
 
Upvote 0
Hello,​
the error raises 'cause you are searching an Id which does not exist …​
Hello Marc,

What do you mean by id which does exist. Which id in the cause does not exist ?
 
Upvote 0

Just check the codeline where the error occurs and compare with the webpage element you wanna grab …​
 
Upvote 0
Just check the codeline where the error occurs and compare with the webpage element you wanna grab …​
Hello Marc,
When I try to run the code differently, I have an error "method of document object "webbrowser2 failed"
VBA Code:
Sub InternetExplorerObject()



Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True
    
IE.Navigate URL:="https://www.amazon.fr/dp/B084CQ41M2/?psc=1", Flags:=navOpenInNewWindow
    
Do While IE.Busy = True
       
Application.Wait Now + TimeValue("00:00:01")
       
Loop
   
Debug.Print IE.LocationURL
    
   
    Dim IEDocument As HTMLDocument
    Set IEDocument = IE.Document
    
    'The simplest thing we can do is grab an element, and then the inner text.
    Debug.Print IEDocument.getElementById("header").innerText
End Sub
 
Upvote 0
As it's still the same code so with the same error …​
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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