I like the area where I can reach the itch.
Please check the genre specification of index = "All" at the link below. Specify product category (SearchIndex)
I think this is pretty good.
import bottlenose
from bs4 import BeautifulSoup
import webbrowser
class Content:
pass
class Amazon():
def __init__(self):
AMAZON_ACCESS_KEY_ID = ""
AMAZON_SECRET_KEY = ""
AMAZON_ASSOC_TAG = ""
self.amazon = bottlenose.Amazon(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, Region="JP")
def search(self,query,index="All"):# index =Genre such as Video
response = self.amazon.ItemSearch(SearchIndex=index, Keywords=query, ItemPage=1, ResponseGroup="Large")
xml = response.decode('utf-8','strict')
soup = BeautifulSoup(xml, "html5lib")
data = soup.findAll('item')
for d in data:
url = d.detailpageurl.text
title = d.title.text.replace("[","【").replace("]","】")
con = Content()
con.asin = d.asin.text
con.amazonjs= '[amazonjs asin="%s" locale="JP"]' % d.asin.text
con.title = title
con.url = url
con.link = '<a href="%s">%s</a>' % (url,title)
con.price = d.formattedprice.text
con.img = d.largeimage.url.text
yield con
class SelectAmazon():
def __init__(self,query,index="All"):
data = list(Amazon().search(query,index=index))
while True:
for i,datum in enumerate(data):
print("%s:%s" % (i,datum.title))
try:
put = int(input('Select a number:'))
break
except:
continue
self.asin = [datum.asin for datum in data][put]
self.title = [datum.title for datum in data][put]
self.url = [datum.url for datum in data][put]
self.price = [datum.price for datum in data][put]
self.img = [datum.img for datum in data][put]
self.amazonjs = [datum.amazonjs for datum in data][put]
self.link = [datum.link for datum in data][put]
def main():
A = SelectAmazon(input("Search word:"),index="All")
webbrowser.open(A.url)
if __name__ == '__main__':
main()
Recommended Posts