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

2024-06-30 16:34:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个基本的“我感觉很幸运”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 "[]"

Tags: import应用程序searchget链接sysresrequests