0

Just started to try using PyQt5 to scrape product price on Amazon. here is the code to connect to the webpage. However, Amazon tends to display different prices depends on your delivery address (I guess the site get this info from the browser cookies if I chose a delivery address before). In the case of using PyQt5, how can I use a custom cookie profile to connect to Amazon and get country-specific pricing information?

class Page(QWebEnginePage): 

    def __init__(self, URL): 
        self.app = QApplication(sys.argv) 
        QWebEnginePage.__init__(self) 
        QWebEngineProfile.__init__(self) 
        self.html = '' 
        self.loadFinished.connect(self._on_load_finished) 
        self.load(QUrl(url)) 
        self.app.exec_() 

    def _on_load_finished(self): 
        self.html = self.toHtml(self.Callable) 
        print('Load finished') 

    def Callable(self, html_str): 
        self.html = html_str 
        self.app.quit() 
Mehdi Mostafavi
  • 880
  • 1
  • 12
  • 25
  • I have analyzed the cookies that amazon uses using google-chrome and I do not see information relevant to the country, I have been able to set a language but that does not change the prices. You could provide as you see that the same product has 2 different prices. I think amazon geolocates the user using the information from the same request. – eyllanesc Aug 25 '20 at 20:23
  • Once I changed the delivery country to e.g Hong Kong, the cookies got one more value sp-cdn:"L5Z9HK". If I change the delivery address back to US, this sp-cdn cookie's value is gone. For example [link](https://www.amazon.com/dp/B078HSVK7M), once you changed the country (to anywhere outside of the US) in the top left "Delivery to" button, the price is gonna to change as well. – Stanley Hung Aug 26 '20 at 07:08

0 Answers0