Мой код
import requests
import json
from bs4 import BeautifulSoup
def scrape(query):
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
ama_id=[]
flipid=[]
query = input("Enter your product: ")
URL_amazon=[]
#Amazon links
query_amazon = "amazon::"+query+" "+"product-reviews"
#
for j in search(query_amazon, tld="co.in", num=10, stop=10, pause=2):
URL_amazon.append(j)
#print(URL_amazon)
import re
for url in URL_amazon:
search = re.search(r'(?:[/dp/]|$)([A-Z0-9]{10})', url)
if search:
#print(search.group(0)[1:])
ama_id.append(search.group(0)[1:])
URL_flipkart=[]
#query = "boAt Rockerz 255"
#Flipkart links
query_flipkart = "flipkart::"+query+" "+"product-reviews"
#print(query_flipkart)
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
for k in search(query_flipkart, tld="co.in", num=10, stop=10, pause=2):
URL_flipkart.append(k)
#print(URL_flipkart)
import urllib.parse as urlparse
from urllib.parse import parse_qs
for url in URL_flipkart:
parsed = urlparse.urlparse(url)
if 'pid' in parse_qs(parsed.query):
#print(parse_qs(parsed.query)['pid'])
flipid.append(parse_qs(parsed.query)['pid'])
ids = {ama_id:"ama_id[]", flipid:"flipid[]"}
return ids
scrape(query)
Ошибка при запуске кода:
TypeError Traceback (most recent call last)
<ipython-input-25-369ff8cc2411> in <module>
55
56 return ids
---> 57 scrape(query)
<ipython-input-25-369ff8cc2411> in scrape(query)
52 flipid.append(parse_qs(parsed.query)['pid'])
53
---> 54 ids = {ama_id:"ama_id[]", flipid:"flipid[]"}
55
56 return ids
TypeError: unhashable type: 'list'