我试图在php中使用curl从goodreads下载列表数据,但它总是为不同的页面返回相同的结果。我的意思是,?page=1
和?page=2
的结果相同。我怎么解决这个问题?抱歉我的英文不好,谢谢。
$data1 = getGoodreadsList("http://www.goodreads.com/list/show/43005.En_yi_T_rk_e_eviriler?page=");
var_dump($data1);
public function getGoodreadsList($link){
$result = [];
for($page=1;$page<29;$page++){
$html = str_get_html($this->downloadUrl($link . strval($page)));
foreach($html->find(".bookTitle") as $book){
array_push($result, "http://www.goodreads.com" . $book->href);
}
$html->clear();
unset($html);
if($page == 2){
break;
}
}
return $result;
}
private function downloadUrl($url){
$headers[] = "User-Agent:'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'";
$headers[] = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$headers[] = "Accept-Language:en-us,en;q=0.5";
$headers[] = "Accept-Encoding:gzip,deflate";
$headers[] = "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$headers[] = "Keep-Alive:115";
$headers[] = "Connection:keep-alive";
$headers[] = "Cache-Control:max-age=0";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_VERBOSE, false);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}