【问题标题】:This code for Web Scraping using python returning None. Why? Any help would be appreciated此代码用于使用 python 返回 None 的 Web Scraping。为什么?任何帮助,将不胜感激
【发布时间】:2020-05-29 21:47:21
【问题描述】:
from bs4 import BeautifulSoup

import requests

headers = {'Use-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/79.0.3945.130 Safari/537.36'}

url = 'https://www.amazon.com/Sony-Alpha-a6400-Mirrorless-Camera/dp/B07MV3P7M8/ref=sr_1_4?keywords=sony+alpha&qid=1581656953&s=electronics&sr=1-4'

page = requests.get(url,headers=headers)

soup = BeautifulSoup(page.content, 'html.parser')

title = soup.find(id="productTitle").get_text()

price = soup.find(id="priceblock_ourprice").get_text()

print(title)

print(price)

【问题讨论】:

标签: python web-scraping beautifulsoup


【解决方案1】:

您的代码工作正常,但在产品页面之前有一个机器人检查,因此您的请求在该机器人检查页面中查找 span 标签,失败并返回 None

这是一个可以帮助你的链接:python requests & beautifulsoup bot detection

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-07
    • 2014-07-03
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多