我想按日期查询谷歌搜索引擎,以获得第一页结果然后处理它。我目前使用的查询返回结果,但不是在我设置的日期范围内;如果我将相同的查询复制到谷歌它适用于日期,但不是从我的PHP脚本。该脚本只返回当前或正常结果,就好像日期参数未设置一样。下面是使用的代码片段的一部分。我所指的查询以及在$ url变量中发布的代码片段中。查询谷歌搜索引擎?
查询:https://www.google.com/search?q='.$Query.'&source=lnt&tbs=cdr%3A1%2'.$startDate.$EndDate.'&tbm=
$Query= $_POST['Query'];
$Query=str_replace(" ","+",$Query);
if ($_POST['Start_date']==''){
$startday='1';
$startmonth='11';
$startyear='2011';
}
if ($_POST['End_date']==''){
$endday='1';
$endmonth='11';
$endyear='2013';
}
$startDate='Ccd_min%3A'.$startmonth.'%2F'.$startday.'%2F'.$startyear.'.%2';
$EndDate='Ccd_max%3A'.$endmonth.'%2F'.$endday.'%2F'.$endyear.'';
if ($_POST['Query']!=''){
$url = 'https://www.google.com/search?
q='.$Query.'&source=lnt&tbs=cdr%3A1%2'.$startDate.$EndDate.'&tbm=';
echo $url .'<p>';
$html = file_get_html($url);
$searchresults=array();
$linkObjs = $html->find('h3.r a');
foreach ($linkObjs as $linkObj) {
$link = trim($linkObj->href);
// if it is not a direct link but url reference found inside it, then extract
if (!preg_match('/^https?/', $link) && preg_match('/q=(.+)&sa=/U', $link, $matches) && preg_match('/^https?/', $matches[1])) {
$link = $matches[1];
} else if (!preg_match('/^https?/', $link)) { // skip if it is not a valid link
continue;
}
array_push($searchresults,$link);
}
感谢您的回复,我有紧急事项要处理,因此我无法回复。你是正确的,当我禁用JavaScript的查询不再使用我指定的日期范围,它只是返回正常结果。你能建议一个可能适用于日期范围的查询吗? – Dario
Google datarange:运营商接受Julian年,即:'daterange:2451607-2451610',您可以发布您使用的查询示例吗? –
查询:https://www.google.com/search?q=pdf&source=lnt&tbs=cdr%3A1%2Ccd_min%3A11%2F1%2F2011.%2Ccd_max%3A11%2F1%2F2013&tbm= – Dario