1. 程式人生 > >amazon爬取亞馬遜頁面信息

amazon爬取亞馬遜頁面信息

爬蟲 pyton



代碼:

# -*- coding: cp936 -*-

import requests

from lxml import etree



ASIN = ‘B00X4WHP5E‘

#ASIN = ‘B017R1YFEG‘

url = ‘https://www.amazon.com/dp/‘+ASIN

r = requests.get(url)

html = r.text


tree = etree.HTML(html)


#獲取產品單價

span = tree.xpath("//span[@id=‘priceblock_ourprice‘]/text()")

print "ASIN碼:",ASIN

print "單價:",span



#獲取產品customer reviews

cus_reviewList = tree.xpath("//div[@id=‘averageCustomerReviews‘]/span/a/span[@id=‘acrCustomerReviewText‘]/text()")

print "Customer Reviews:",cus_reviewList[0]


#獲取產品kc


amazon爬取亞馬遜頁面信息