Automate the boring stuff with python - google search via beautiful soup 4

蓝咒 提交于 2019-12-25 01:48:56

问题


Has anyone had trouble calling browser after executing the code mentioned below?

I have executed code from Pycharm version 2019.1 and I have done it from CMD but no results.

My Code:

import requests
import sys
import webbrowser as wb
import bs4

print ('Googling...')
res = requests.get('http://google.com/search?q='+''.join(sys.argv[1:]))
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'lxml')
linkElements = soup.select('.r a')
linkToOpen = min(5, len(linkElements))
for i in range(linkToOpen):
   wb.open('http://google.com'+linkElements[i].get('href'))

No error messages, unable to call the browser.

来源:https://stackoverflow.com/questions/56542180/automate-the-boring-stuff-with-python-google-search-via-beautiful-soup-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!