在尝试运行我的脚本时出现问题任何建议 . 当我运行我的脚本时,我收到一个声明“UserWarning:没有明确指定解析器,所以我使用了最好的HTML解析器(”html.parser“) . 这通常不是问题,但如果你在另一个系统或另一个虚拟环境中运行此代码,它可能使用不同的解析器,行为也不同 .

导致此警告的代码位于文件/home/maddawg/Scripts/lucky.py的第13行 . 要摆脱此警告,请将附加参数'features =“html.parser”'传递给BeautifulSoup构造函数 .

soup = bs4.BeautifulSoup(res.text)“所以当我尝试从命令行运行它时,它将无法提供任何建议吗?

!在/ usr / bin中/ python3

lucky.py - 打开多个谷歌搜索结果 .

import requests
import sys
import webbrowser
import bs4
    print('Googling...') # display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:]))
res.raise_for_status()

soup = bs4.BeautifulSoup(res.text)

LinkElems = soup.select('.r a')
numOpen = min(5, len(LinkElems))
for i in range(numOpen):
    webbrowser.open('http://google.com/' + LinkElems[i].get('href'))