被毒贩控制的墨西哥,有多恐怖?
2024-10-29 14:55:42
谷歌搜索库:googlesearch-python
googlesearch是一个Python库,可轻松爬取Google搜索结果。googlesearch使用requests和
BeautifulSoup4抓取Google。
要安装,请运行以下命令:
python3 -m pip install googlesearch-python 或者 pip3 install googlesearch-python
要获取搜索字词的结果,只需使用googlesearch中的搜索功能。例如,要在Google中获取“ 高效码农”的结果,只需运行以下程序:
from googlesearch import search import pprint list = search("高效码农") pprint.pprint(list)
打印结果:
['https://www.xugj520.cn/', 'https://blog.csdn.net/Java_supermanNO1/article/details/104536476', 'https://weekly.manong.io/issues/295', 'https://c.quk.cc/3/b92c/lne1b5c12h1 'https://c.quk.cc/3/b92c/tqkc10aiuwt 'https://c.quk.cc/3/b92c/cr5n2rmojhv 'https://my.oschina.net/u/1189098', 'https://www.codercto.com/a/98794.html', 'https://www.cnblogs.com/huang0925/p/3612741.html', 'https://www.jiqizhixin.com/users/0d71c15b-b934-482a-aadc-5f5cf63afd60']
googlesearch支持其他一些选项。默认情况下,googlesearch返回10个结果。这可以更改。例如,要在Google上获得100个结果,请运行以下程序。
from googlesearch import search import pprint list = search("高效码农", num_results=100) pprint.pprint(list)
此外,您可以更改Google搜索的语言。例如,要获取法语结果,请运行以下程序:
list = search("高效码农", num_results=100, lang='fr')
完整API:
googlesearch.search(str: term, int: num_results=10, str: lang="en") -> list
修改__init__.py 第5行为:
def search(term, proxies, num_results=10, lang="en"):
修改__init__.py 第15行为:
response = get(google_url, headers=usr_agent, proxies=proxies)
使用代码修改为:
list = search("高效码农", proxies=proxies, num_results=100, lang='fr')
完整代码为:
from googlesearch import search import pprint proxies = {"http": '127.0.0.1:1087', "https": '127.0.0.1:1087', } result = search("高效码农", proxies=proxies, num_results=100, lang='fr') pprint.pprint(result)
2024-10-29 14:55:42
2024-10-29 14:53:28
2024-10-29 14:51:14
2024-10-29 14:49:00
2024-10-29 06:36:48
2024-10-29 06:34:33
2024-10-29 06:32:19
2024-10-29 06:30:05
2024-10-29 06:27:51
2024-10-29 06:25:37
2024-10-29 06:23:22
2024-10-29 06:21:08
2024-10-29 06:18:54
2024-10-29 06:16:40
2024-10-29 06:14:26
2024-10-29 06:09:57
2024-10-29 06:07:43
2024-10-29 06:05:29
2024-10-29 06:03:14