尝试进行网络抓取时,我的代码不打印任何内容

时间:2020-05-19 20:08:19

标签: python web-scraping

我是一个刚开始学习Python的新手,一周前,我试图在亚马逊上获取特定产品的产品标题,但是当我尝试运行我的代码时,它会显示“ None”而不是显示标题Any帮助吗?

import requests
from bs4 import BeautifulSoup

url = 'https://www.amazon.com/Sony-ILCE7SM2-mount-Camera-Full-Frame/dp/B0158SRJVQ/ref=sr_1_1?        
dchild=1&keywords=a7s&qid=1589917834&sr=8-1'
headers = {
    'user_agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like 
Gecko) Chrome/81.0.4044.138 Safari/537.36'
}

page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')

title = soup.find(id='productTitle')

print(title)

0 个答案:

没有答案