Skip to main content
 首页 » 编程设计

python之如何使用 python 获得不是广告的 Google 搜索的第一个结果

2024年10月01日6lyhabc

我正在尝试获取许多澳大利亚公司的财务报表 pdf 格式。我将所有公司都存储在 pandas 数据框中,他们的公司名称位于名为“公司”的列中这是我到目前为止用于搜索 url 的代码:

import webbrowser 
 
tabUrl = "http://google.com/?#q=" 
append = "+financial+report+2017" 
file_type = 'filetype%3Apdf+' 
 
for company in data["Company"]: 
        googleSearch = tabUrl + file_type + company.replace(" ", "+") + append 
        print(googleSearch) 

每次搜索都会(不出所料)返回许多广告作为第一个结果。如何打开第一个不是广告的结果?

谢谢!

请您参考如下方法:

现在您正在向 google 网页 url 发送请求,如果您转到 https://www.google.com,显示的结果将包含您在 google 上看到的广告。

更好的方法是使用谷歌 Custom Search API发送您的请求并获得结果。您可以在此处获取文档:https://developers.google.com/custom-search/json-api/v1/using_rest

从他们的文档中,您可以看到您可以制作 REST在您生成API KEY 和自定义搜索引擎 ID

后向他们的服务端点发出请求
GET https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures