如何使用BeautifulSoup在Python中解析Google搜索结果

如何使用BeautifulSoup在Python中解析Google搜索结果,第1张

如何使用BeautifulSoup在Python中解析Google搜索结果

您的网址对我不起作用。但是有了

https://google.com/search?q=
结果。

import urllibfrom bs4 import BeautifulSoupimport requestsimport webbrowsertext = 'hello world'text = urllib.parse.quote_plus(text)url = 'https://google.com/search?q=' + textresponse = requests.get(url)#with open('output.html', 'wb') as f:#    f.write(response.content)#webbrowser.open('output.html')soup = BeautifulSoup(response.text, 'lxml')for g in soup.find_all(class_='g'):    print(g.text)    print('-----')

阅读美丽汤文档



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5648859.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存