我正在尝试从 Google Scholar 个人资料页面中抓取。我的想法是我想使用 XPath 检索出版物列表,但我没有下载该页面,这是我的代码:我尝试使用 curl
function get_page($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
//I tried to change user agent as well
//curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
并且没有 curl :
function get_xpath($query_url) {
$dom = new DOMDocument();
@$dom->loadHTMLFile($query_url);
sleep(1);
return new DOMXpath($dom);
}
$query_url = "https://scholar.google.it/citations?user=p-POZjgAAAAJ&hl=it&cstart=0&pagesize=100";
得到它没有卷曲
$xpath = get_xpath($query_url);
用 curl 得到它
$xpath = get_xpath(get_page($query_url));
接着
$autori=$xpath->query("//tr[1]/td[1]/div[1]");
但是 $autori 一直是空的,知道吗?