使用 Google Search API 时如何输入日期限制? [英] how can I enter a date restriction when using the Google Search API?

查看:26
本文介绍了使用 Google Search API 时如何输入日期限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Google 搜索 API 并根据结果仅存在一天这一事实来查找结果.我可以通过 Google 搜索引擎执行此操作,但我似乎找不到使用 API 执行此操作的方法.

I'm wanting to use the Google Search API and find results based on the fact that they are only a day old. I can do this through the Google search engine but I can't seem to find a way to do this by using the API.

我的代码:$googleFullURL = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&start=$searchIndex&lr=lang_en&filter=0&q=$searchTerms";

my code: $googleFullURL = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&start=$searchIndex&lr=lang_en&filter=0&q=$searchTerms";

我尝试在搜索结束时使用&tbs=,qdr:d",这是搜索引擎在限制日期范围时附加在 URL 末尾的内容,但这似乎不起作用.

I tried using "&tbs=,qdr:d" at the end of my search which is what the search engine appends at the end of the URL when restricting to a date range but this seems to not be working.

谢谢

推荐答案

您想使用 dateRestrict 参数,它是一个字符串.

You want to use the dateRestrict parameter which is a string.

将结果限制为基于日期的 URL.支持的值包括:

Restricts results to URLs based on date. Supported values include:

  • d[number]:请求过去指定天数的结果.
  • w[number]:请求过去几周指定数量的结果.
  • m[number]:请求过去几个月指定数量的结果.
  • y[number]:请求过去指定年份的结果.

<小时>

参数文档:https://developers.google.com/custom-search/json-api/v1/reference/cse/list

这篇关于使用 Google Search API 时如何输入日期限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆