这是我的代码,在我使用它时没有出现错误之前它工作正常。我不明白这是怎么发生的,尽管我没有随之改变。 :
results = []
for query in my_list:
results.append(search(query, tld="com", num=1, stop=1, pause=2))
错误:
results.append(search(query, tld="com", num=1, stop=1, pause=2))
TypeError: search() got an unexpected keyword argument 'tld'
它来自
google
python 包。所有版本仍然有效。
query
:我们要搜索的查询字符串。tld
:tld 代表顶级域名,这意味着我们要在 google.com 或 google.in 或其他域名上搜索结果。lang
:lang 代表语言。num
:我们想要的结果数量。start
:要检索的第一个结果。stop
:要检索的最后结果。使用 None 来永远继续搜索。pause
:HTTP 请求之间的等待时间间隔。间隔太短可能会导致 Google 屏蔽您的 IP。保持明显的失误会让你的程序变慢,但它是安全且更好的选择。Return
:生成找到的 URL 的生成器(迭代器)。如果 stop 参数为 None ,迭代器将永远循环。还有一个Python包,模块名称为
googlesearch
链接这里
由于它可能安装在您的环境中,因此可能会调用不包含这些参数的模块。
pip install beautifulsoup4
和pip install google
pip install googlesearch-python
python 包需要安装
google
库,安装此库停止产生错误:
pip install google
我遇到了同样的问题,但找到了解决方法 我面临的问题是我在“def search()”函数之外导入了“search”函数,如下所示
from googlesearch import search
def search(query):
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
urls.append(j)
我得到了你得到的错误
所以我的解决方法是在我的搜索函数中导入 googlesearch.search 函数,如下所示
def search(query):
try:
from googlesearch import search
except:
pass
urls = []
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
urls.append(j)
url = str(urls[0])
这为我解决了这个问题 让我知道它是否适合你