无法让我的基本Webscraper启动Google

时间:2019-10-13 13:40:58

标签: python scrape

我正在尝试测试基本的webscraper脚本,并想尝试使用终端。当我运行脚本时,不执行任何搜索。知道为什么吗?

# lucky2.py - Opens several Google search results.

import requests, sys, webbrowser, bs4

ask = input('What do you want to google?')
print('Googling...') #Display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + str(ask) .join(sys.argv[1:]))
res.raise_for_status()

#TODO: Retrieve top search result links.

#TODO: Open a browser tab for each result.

# Retrieve top search result links.
soup = bs4.BeautifulSoup(res.text)

# Open a browser tab for each result
linkElems = soup.select('.r a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
    webbrowser.open('http://google.com' + linkElems[i].get('href'))

```Thanks!!

0 个答案:

没有答案