提取 Google 搜索结果
我想定期检查 Google 列出了哪些子域。
要获取子域列表,我在 Google 搜索框中输入“site:example.com” - 这会列出所有子域结果(我们的域有 20 多个页面)。
仅提取“site:example.com”搜索返回的地址的 URL 的最佳方法是什么?
我正在考虑编写一个小 python 脚本,该脚本将执行上述搜索并正则表达式搜索结果中的 URL(在所有结果页面上重复)。这是一个好的开始吗?是否有更好的方法论?
干杯。
I would like to periodically check what sub-domains are being listed by Google.
To obtain list of sub-domains, I type 'site:example.com' in Google search box - this lists all the sub-domain results (over 20 pages for our domain).
What is the best way to extract only the URL of the addresses returned by the 'site:example.com' search?
I was thinking of writing a little python script that will do the above search and regex the URLs from the search results (repeat on all result pages). Is this a good start? Could there be a better methodology?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于解析 HTML 来说,正则表达式不是一个好主意。它读起来很神秘,并且依赖于格式良好的 HTML。
尝试使用 Python 版 BeautifulSoup。下面是一个示例脚本,它返回 site:domain.com Google 查询的前 10 页的 URL。
输出:
当然,您可以将每个结果附加到列表中,以便可以解析它的子域。几天前我刚刚开始学习 Python 并进行抓取,但这应该可以帮助您入门。
Regex is a bad idea for parsing HTML. It's cryptic to read and relies of well-formed HTML.
Try BeautifulSoup for Python. Here's an example script that returns URLs from the first 10 pages of a site:domain.com Google query.
Output:
Of course, you could append each result to a list so you can parse it for subdomains. I just got into Python and scraping a few days ago, but this should get you started.
Google Custom Search API 可以提供ATOM XML 格式的结果
Google 入门自定义搜索
The Google Custom Search API can deliver results in ATOM XML format
Getting Started with Google Custom Search
另一种使用
requests
、bs4
的方法:输出:
要使用分页从每个页面获取这些结果:
部分输出:
或者,您可以使用 Google 搜索引擎结果 API。它是一个付费 API,可免费试用 5,000 次搜索。
要集成的代码:
输出:
使用分页:
Another way of doing it using
requests
,bs4
:Output:
To get these results from each page using pagination:
Part of the output:
Alternatively, you can use Google Search Engine Results API from SerpApi. It's a paid API with a free trial of 5,000 searches.
Code to integrate:
Output:
Using pagination: