【问题标题】:Trying to get product title from Amazon Review Url试图从亚马逊评论网址获取产品标题
【发布时间】:2021-01-10 20:26:57
【问题描述】:
【问题讨论】:
标签:
python
web-scraping
beautifulsoup
amazon
【解决方案1】:
您可能有验证码页面。尝试指定不同的 HTTP 标头(在我的情况下为 User-Agent 和 Accept-Language):
import requests
from bs4 import BeautifulSoup
url = 'https://www.amazon.com/Marmot-womens-Precip-Lightweight-Waterproof/product-reviews/B086YML34N/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Accept-Language': 'en-US,en;q=0.5'}
soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')
print(soup.select_one('h1.a-size-large.a-text-ellipsis').text)
打印:
Marmot womens Precip Lightweight Waterproof Rain Jacket
【解决方案2】:
因为 bs4 中没有 findall。它是find_all 或findAll(大写A)。