Last active
December 2, 2015 19:51
-
-
Save vagelim/3ad4937d6f0cd914aa7e to your computer and use it in GitHub Desktop.
scrape Amazon multiple price page for lowest price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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