import requests
from bs4 import BeautifulSoup
import csv
from datetime import datetime
r = requests.get('http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=hp+laptops')
from bs4 import BeautifulSoup
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find_all('ul', attrs={'class':'class="s-result-list s-col-1 s-col-ws-1 s-result-list-hgrid s-height-equalized s-list-view s-text-condensed s-item-container-height-auto"'})
records = []
for result in results:
name = result.findAll('h2', attrs={'class':'a-size-medium s-inline s-access-title a-text-normal'}).text # result not results
price = result.findAll('span', attrs={'class':'a-size-base a-color-price s-price a-text-bold'}).text[13:-11]
records.append((name, price,))
with open('indd.xls', 'a') as csv_file:
writer = csv.writer(csv_file)
for name, price in records:
writer.writerow([name, price, datetime.now()])
答案 0 :(得分:0)
如果您阅读了回复,您会看到:
To discuss automated access to Amazon data please contact api-services-support@amazon.com.
For information about migrating to our APIs refer to our Marketplace APIs at https://developer.amazonservices.in/ref=rm_c_sv, or our Product Advertising API at https://affiliate-program.amazon.in/gp/advertising/api/detail/main.html/ref=rm_c_ac for advertising use cases.