【发布时间】:2020-08-31 11:32:46
【问题描述】:
我是 python 新手,我正在向automating boring stuff with python 学习,所以目前我在本书的网络抓取章节中。所以,我只想抓取搜索结果的标题。
这是我的代码-
import requests
from bs4 import BeautifulSoup
import webbrowser
term = 'python'
req = requests.get('https://www.google.com/search?q=' + term)
req.raise_for_status()
soup = BeautifulSoup(req.text, 'lxml')
title = soup.find('div', class_ = 'r')
print(title)
问题是它总是返回None。我什至攻击了检查元素工具的屏幕截图,以便您可以看到我正在使用的 div 和 class 名称。
感谢任何帮助 谢谢
【问题讨论】:
标签: python web-scraping beautifulsoup python-requests