我目前面临的问题是,我无法抓取我想要从部落网站获取的信息。Python抓取JSON - 获取所有项目
详细地说,我想获得所有的项目和价格观看返回的JSON。
到目前为止,我能够获得所有的价格,但缺乏所有的项目,以及回来。我只是回来一个特定的项目。
不知道是什么问题。
这是我的逻辑至今:
session = requests.Session()
session.cookies.get_dict()
url = 'http://www.citydis.com'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
response = session.get(url, headers=headers)
soup = BeautifulSoup(response.content, "html.parser")
metaConfig = soup.find("meta", property="configuration")
jsonUrl = "https://www.citydis.com/s/results.json?&q=London& customerSearch=1&page=0"
js_dict = (json.loads(response.content.decode('utf-8')))
for item in js_dict:
header = (js_dict['searchResults']["tours"])
for titles in header:
title_final = (titles.get("title"))
url = (js_dict['searchResults']["tours"])
for urls in url:
url_final = (urls.get("url"))
price = (js_dict['searchResults']["tours"])
for prices in price:
price_final = (prices.get("price")["original"])
print("Header: " + title_final + " | " + "Price: " + price_final)
那输出:
Header: Ticket für Madame Tussauds London & Star-Wars-Erlebnis | Price: 83,66 €
Header: Ticket für Madame Tussauds London & Star-Wars-Erlebnis | Price: 37,71 €
Header: Ticket für Madame Tussauds London & Star-Wars-Erlebnis | Price: 152,01 €
正如你们所看到的,价格都显示正常,但项目(头)没有什么不同。我只是回来一个特定的项目。
你们能帮我吗?任何反馈意见。
感谢您的帮助。欣赏它。但现在我得到了price.get的以下错误:price_final = prices.get(“price”)[“original”] AttributeError:'list'object has no attribute'get'你有任何意见吗?对不起,我对python很陌生 –