【发布时间】:2020-11-21 09:39:24
【问题描述】:
在 Python 中使用 requests.get() 方法时,我得到的响应对象产生的 html 代码与我从浏览器 (Chrome) 获得的源代码不同。这让我很难使用 BeautifulSoup 模块解析代码。
有什么解决办法吗?我有什么错误吗?
下面给出的是我的 python 脚本。我从 chrome 获得的网页源代码在 r 类中有一个 a id,该类有一个 href 链接。所以我想我会得到一个链接。但它一直返回一个空列表。
import requests,bs4,webbrowser
res=requests.get('https://www.google.com/search?q=wind+river')
soup=bs4.BeautifulSoup(res.text, 'lxml')
sel=soup.select('.r a')
sel[0].get('href')
【问题讨论】:
-
Google 将阻止您,否则他们将发送验证码
-
@bigbounty 为什么会这样?
-
这就是他们设计网站的方式
标签: python html beautifulsoup python-requests html-parsing