Python从Google搜索中获取特色片段

2024-06-16 12:36:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python的模块“google”,我想解析链接上方的特色片段。
现在,我有了这个代码:

from google import google
num_page = 1
search_results = google.search("ally subsidiaries", num_page)
for result in search_results:
    print(result.name)

示例:
ally finance

如何解析链接上方表中的数据?(表ally financial->子公司)
我的代码只提供特色代码片段下面的链接。在


Tags: 模块代码fromimportforsearch链接google
1条回答
网友
1楼 · 发布于 2024-06-16 12:36:12

Google Search Featured Snippet

实际上,您正试图从上面的featured snippet(搜索结果上方的表)中提取数据。不幸的是,google包并没有提供解决方案。在

{你可以试试这个。serpapi真的很快,并且提供了很多特性,比如从特色片段中提取数据。在

尝试下面的API请求并查看结果。在

https://serpapi.com/search.json?q=ally+subsidiaries&location=United+States&hl=en&gl=us&source=homepage&async=true

您可以检查响应here。在

^{pr2}$

相关问题 更多 >