选择谷歌搜索的一部分时没有给出输出



我正在制作一个基本的"我感觉很幸运"的Python应用程序,但是当我尝试选择链接时,它什么也没返回。

import requests, webbrowser, bs4, sys
print('Googling...')
res = requests.get('https://google.com/search?q=%s' % sys.argv[1])
if res.status_code != 200:
print('Invalid input')
sys.exit()
res = res.text
soup = bs4.BeautifulSoup(res, features='html.parser')
search = soup.select('.r') # trying to select the class "r"
print(search) # returns "[]"

发生这种情况是因为Google发送的是重定向页面,而不是结果页面。这会阻止系统工作。

最新更新