【问题标题】:Trying to get product title from Amazon Review Url试图从亚马逊评论网址获取产品标题
【发布时间】:2021-01-10 20:26:57
【问题描述】:

我使用的网址是: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

product_name = soup.findall("h1",{"class":"a-size-large a-text-ellipsis"})

我正在尝试获取页面上所有评论的产品标题。我尝试使用上面的代码,但出现“nonetype”错误。我代码中的其他属性确实有效。我在想我没有选择正确的课程。有没有人有从亚马逊抓取的经验,可以就我做错了什么提供一些建议?

【问题讨论】:

    标签: python web-scraping beautifulsoup amazon


    【解决方案1】:

    您可能有验证码页面。尝试指定不同的 HTTP 标头(在我的情况下为 User-AgentAccept-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_allfindAll(大写A)。

      【讨论】:

        猜你喜欢
        • 2013-07-22
        • 1970-01-01
        • 2012-01-31
        • 1970-01-01
        • 1970-01-01
        • 2020-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多