我正在使用 curl 为linkedin 个人资料页面进行网络抓取。如果我们尝试从这个 ( http://in.linkedin.com/in/ratneshdwivedi ) 公开的 URL 中提取数据,它就可以工作。当我登录到linkedin并试图从这个URL(http://www.linkedin.com/profile/view?id=77597832&locale=en_US&trk=tyah2&trkInfo=tas%3Aravi%20kant%20mishra%2Cidx%3A1- 1-1 ) 它不工作,而是返回空白数据。
以下是我的源代码:
$html= $this->_getScrapingData ('http://in.linkedin.com/in/ratneshdwivedi',10);
preg_match("/<span class=\"full-name\">(.*)<\/span>/i", $html, $match);
private function _getScrapingData($url,$timeout) {
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
return @curl_exec($ch);
}
提前致谢