开发者

How to get contents of Amazon shopping cart?

I've been investigating whether it's possible to get a list of the saved items in my Amazon shopping basket programmatically.

Their Product Advertising API has methods for getting wishlists described here and working with remote shopping carts described here.

But the shopping cart of items stored while on the Amazon web site is treated as a local shopping cart, and therefore is not accessible through the Product Adverti开发者_如何学Gosing API.

According to the last link:

The opposite of a remote shopping cart is a local shopping cart, which is the shopping cart customers use while shopping on www.amazon.com. It is considered local because Amazon hosts the shopping web pages as well as the shopping cart. Product Advertising API operations work solely with remote shopping carts.

Has anyone found a way of getting the contents of the "local" cart, apart from scraping the HTML?


It appears that Amazon does not offer this in their API. However, depending on what your environment is it may be possible to do this without using the API by having the user sign in and doing a page scrape of the shopping cart page.

This link may be useful: http://bililite.com/blog/2010/10/31/hacking-my-way-to-an-amazon-wishlist-widget/


I know this is a 10 year old question, but here is a way to do it using python3.

import browser_cookie3
import requests

cookies = browser_cookie3.chrome(domain_name='.amazon.com')
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36'
}

with requests.session() as s:
    s.cookies = cookies
    s.headers = headers
    url = 'https://www.amazon.com/gp/cart/view.html?ref_=nav_cart'

    resp = s.get(url)
    print('resp text contains shopping cart data')

You can use something like BeautifulSoup to parse response text. In order for this to work the user must be signed into Amazon in Chrome. browser_cookie3 can be set to use other browsers as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜