http://www.taodaxiang.com/credit/index/init
這個頁面需要post查詢後。在抓取查詢的資料。這個用php怎麼寫?求代碼
回複討論(解決方案)
建議你參考一下CURL
百度一下有很多
不行。百度的都抓取失敗。
沒有人嗎?
curl 就可以,不過查詢到的資訊是通過 app_init.js 動態寫入頁面的
所以你還需抓取 app_init.js 後自行解析
比如取回的頁面中有
註冊時間:實名認證:
app_init.js 中有
$("#info_regtime").html(""+data.regtime+"");$("#info_auth").html(""+data.auth+"");
curl 這個好像不用你說喲。php抓取三種方式,我都試過了。就是抓取失敗。所以才來發帖求助
js?入dom的,需要curl後再分析,再curl?取的。
我試了下只能抓取到一個空頁面(就一個[] 內容),應該是做了只能本網站提交表單的限制
authentication = 0; if($use == true) $this->authentication = 1; } public function setName($name){ $this->auth_name = $name; } public function setPass($pass){ $this->auth_pass = $pass; } public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false) { $this->_url = $url; $this->_followlocation = $followlocation; $this->_timeout = $timeOut; $this->_maxRedirects = $maxRedirecs; $this->_noBody = $noBody; $this->_includeHeader = $includeHeader; $this->_binaryTransfer = $binaryTransfer; $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt'; } public function setReferer($referer){ $this->_referer = $referer; } public function setCookiFileLocation($path) { $this->_cookieFileLocation = $path; } public function setPost ($postFields) { $this->_post = true; $this->_postFields = $postFields; } public function setUserAgent($userAgent) { $this->_useragent = $userAgent; } public function createCurl($url = 'nul') { if($url != 'nul'){ $this->_url = $url; } $s = curl_init(); curl_setopt($s,CURLOPT_URL,$this->_url); curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:')); curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout); curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects); curl_setopt($s,CURLOPT_RETURNTRANSFER,true); curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation); curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation); curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation); if($this->authentication == 1){ curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass); } if($this->_post) { curl_setopt($s,CURLOPT_POST,true); curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields); } if($this->_includeHeader) { curl_setopt($s,CURLOPT_HEADER,true); } if($this->_noBody) { curl_setopt($s,CURLOPT_NOBODY,true); } /* if($this->_binary) { curl_setopt($s,CURLOPT_BINARYTRANSFER,true); } */ curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent); curl_setopt($s,CURLOPT_REFERER,$this->_referer); $this->_webpage = curl_exec($s); $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE); curl_close($s); } public function getHttpStatus() { return $this->_status; } public function __tostring(){ return $this->_webpage; }}$m=new mycurl("http://www.taodaxiang.com/credit/index/get");$m->setReferer("http://www.taodaxiang.com/credit/index/init");$m->setPost(Array("account"=>"cupjava"));$m->createCurl();echo $m;?>
json結果出來解析一下就好了
9樓是神人。萬分感謝,可以了