【发布时间】:2020-01-16 05:14:08
【问题描述】:
我想将谷歌搜索结果抓取到第 2 页,但我的网站空白页或超时的结果出现问题。
for($j=0; $j<$acount; $j++){
sleep(60);
for($sp = 0; $sp <= 10; $sp+=10){
$url = 'http://www.google.'.$lang.'/search?q='.$in.'&start='.$sp;
if($sp == 10){
$datenbank = "proxy_work.php";
$datei = fopen($datenbank,"a+");
fwrite($datei, $data);
fwrite ($datei,"\r\n");
fclose($datei);
} else {
$datenbank = "proxy_work.php";
$datei = fopen($datenbank,"w+");
fwrite($datei, $data);
fwrite ($datei,"\r\n");
fclose($datei);
}
}
$html = file_get_html("proxy_work.php");
foreach($html->find('a') as $e){
// $title = $h3->innertext;
$link = $e->href;
if(in_array($endomain, $approveurl)){
}
// 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;
}
}
}
【问题讨论】:
-
为什么要开始一个关于这个的新线程?留在这个:stackoverflow.com/questions/59747547/…
-
就像你关于这个问题的第一个问题一样......没有行代码,你尝试获取请求页面的结果,你只定义了 URL。
-
与本主题不同。本主题是关于最多抓取 2 页,但本主题仅讨论抓取第 2 页。[链接]stackoverflow.com/questions/59747547/…
-
CodyKL 我通过将结果保存在文件名 proxy_work.php 上来获得请求页面上的结果
标签: php web-scraping scrape