fix: some google search result raise exception (#4567)

This commit is contained in:
非法操作 2024-05-22 14:28:52 +08:00 committed by GitHub
parent 3ab19be9ea
commit 24576a39e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -99,8 +99,11 @@ class SerpAPI:
): ):
toret = res["knowledge_graph"]["description"] + "\n" toret = res["knowledge_graph"]["description"] + "\n"
if "snippet" in res["organic_results"][0].keys(): if "snippet" in res["organic_results"][0].keys():
for item in res["organic_results"]: toret = "\n".join(
toret += "content: " + item["snippet"] + "\n" + "link: " + item["link"] + "\n" f"content: {item['snippet']}\nlink: {item['link']}"
for item in res["organic_results"]
if "snippet" in item and "link" in item
)
if ( if (
"images_results" in res.keys() "images_results" in res.keys()
and "thumbnail" in res["images_results"][0].keys() and "thumbnail" in res["images_results"][0].keys()