Skip to content

Instantly share code, notes, and snippets.

@vagelim
Last active December 2, 2015 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vagelim/3ad4937d6f0cd914aa7e to your computer and use it in GitHub Desktop.
Save vagelim/3ad4937d6f0cd914aa7e to your computer and use it in GitHub Desktop.
scrape Amazon multiple price page for lowest price
#Configuration variables
BASE_URL = "http://www.amazon.com/gp/offer-listing/"
XPATH_SELECTOR = '//body//*[@class="a-size-large a-color-price olpOfferPrice a-text-bold"]'
USER_AGENT = {'User-agent': 'Mozilla/5.0'}
ITEM = '1429218274'
import requests
from lxml import html
page = requests.get(BASE_URL + ITEM, headers=USER_AGENT)
tree = html.fromstring(page.text)
t = tree.xpath(XPATH_SELECTOR)[0].text
j = t[t.find('$') : ]
digits = '0123456789.'
price = float(''.join(c for c in t if c in digits))
print price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment