如何使用 python 获取非广告的 Google 搜索的第一个结果?

How can I get the first results of a Google Search that is not an ad using python?

我正在尝试获取许多澳大利亚公司的财务报表 pdf 格式。我将所有公司都存储在一个 pandas 数据框中,他们的公司名称在一个名为 'Companies' 的列中 这是我到目前为止搜索 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)

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

谢谢!

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

更好的方法是使用 google Custom Search API to send your requests and get the results. You can get the documentation here: https://developers.google.com/custom-search/json-api/v1/using_rest

从他们的文档中,您可以看到,一旦您生成 API KEY 和 [=20,就可以向他们的服务端点发出 REST 请求=]自定义搜索引擎ID

GET https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures