简体   繁体   English

在 python 中抓取特定日期范围的 Google 搜索结果

[英]Scrape Google search results of specific date range in python

I am trying to build a system that allows me to pull Google search results of specific date range to my local machine.我正在尝试构建一个系统,允许我将特定日期范围的谷歌搜索结果拉到我的本地机器上。 I tried the following code:我尝试了以下代码:

import requests, bs4

res =
requests.get('https://www.google.com/search?q=nepal+OR+नेपाल&tbs=cdr:1,cd_min:4/1/2020,cd_max:4/8/2020')
res.raise_for_status()

soup = bs4.BeautifulSoup(res.text, 'html.parser') 
linkElements = soup.select('div')

 open('output.html', 'w').write(res.text)

It generates the result as shown in image shown in the following image.它生成的结果如下图所示。 No date range没有日期范围

It is showing a normal search result for 'nepal OR नेपाल' but I need the search results for a date range lets say April 1, 2020 to April 8, 2020 as shown in the image它显示了“尼泊尔 OR नेपाल”的正常搜索结果,但我需要某个日期范围的搜索结果,比如2020 年 4 月 1 日到 2020 年 4 月 8 日,如图所示

With some research, I came to know that this can be done by the use of APIs such as SerpAPI but that will cost me 50$ per month.通过一些研究,我了解到这可以通过使用SerpAPI等 API 来完成,但这将花费我每月 50 美元。

Is there any other way I could do this?有没有其他方法可以做到这一点?

I would suggest you try out selenium unlike requests it can interact with the page once it's there and you can execute JavaScript commands to set a date range.我建议您尝试 selenium 与请求不同,它可以与页面交互,并且您可以执行 JavaScript 命令来设置日期范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM