⑴ php怎麼抓取這個鏈接https://locate.apple.com/cn/zh/service/pt=3&lat=23.134521&lon=113.358803的源碼
<?php
function dg_string($data,$flagA, $flagB, $start = 0){//配套截取字元串
$flagAL=strlen($flagA);
$flagBL=strlen($flagB);
$rn='';
$a=$b=0;
if(($findA=strpos($data,$flagA, $start))!==false){
$a=1;
$tmpA=$findA;
$findB=$findA+$flagAL;
$findA=$findB;
while($a!=$b){
if(($findB = strpos($data, $flagB, $findB))!==false){
$b++;
if(($findA = strpos($data, $flagA, $findA))!==false){
if($findA>$findB){
if($a==$b){
//結束
$findB+=$flagBL;
$rn=substr($data,$tmpA,$findB-$tmpA);
} else {
$a++;
$findB=$findA+$flagAL;
$findA=$findB;
}
} else {
$a++;
$findA+=$flagAL;
$findB+=$flagBL;
}
} else {
if($a==$b){
//結束
$findB+=$flagBL;
$rn=substr($data,$tmpA,$findB-$tmpA);
} else {
//標記不完整
$findB+=$flagBL;
}
}
} else {
//標記不完整
$rn=substr($data,$tmpA);
$rn.=str_repeat($flagB,$a-$b);
break;
}
}
}
return $rn;
}
$html = file_get_contents('https://locate.apple.com/cn/zh/service/?pt=3&lat=23.134521&lon=113.358803');//獲取源碼
$find = strpos($html, 'window.resourceLocator.setup');
$json1 = dg_string($html, '{', '}', $find);//獲取第一個JSON數據
$find = strpos($html, 'window.resourceLocator.storeSetup');
$json2 = dg_string($html, '{', '}', $find);//獲取第二個JSON數據
$arr1 = json_decode($json1, true);//第一個JSON數據轉為數組
$arr2 = json_decode($json2, true);//第二個JSON數據轉為數組
print_r($arr1);
print_r($arr2);
//得到了數組,你想獲取哪個參數都行了,你自己看著辦吧,樓主可親測代碼
?>
⑵ php https數據採集
1:curl抓取html
2:用正則截取你需要的內容,或則用explode分割獲取內容,還有phpquery等可以像jquery一樣使用選擇器獲取你需要的內容
⑶ PHP怎樣處理HTTPS請求
您好,我來為您解答:
$context = stream_context_create(array('ssl' =>array(
'local_cert' =>'./https.pem',
)));
if(!$server = stream_socket_server("ssl 0.0.0.0:2016", $err_no, $err_msg, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context)){
exit($err_msg);
}
while(1){
$client = stream_socket_accept($server);
if ($client) {
stream_set_blocking($client, 0);
$in = '';
while($ret = fread($client, 8192)) $in .= $ret;
$response = "HTTP/1.0 200 OK\r\n\r\nHello";
fwrite($client, $response);
fclose($client);
}
}
希望我的回答對你有幫助。
⑷ 怎麼用phpquery抓取網頁實時數據使用CI框架
phpquery和框架並無關系,我現在也是用CI的
先將pq引入進來
$content = file_get_content('https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do');
phpQuery::newDocumentHTML($content);
$containers = pq("xxxx");就可以了,但你要抓取這個網站數據,他數據是js載入的,所以你只需要
$content = file_get_content('https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery!list.do?_search=false&dataSet.nd=1440145968553&dataSet.rows=100&dataSet.page=1&dataSet.sidx=&dataSet.sord=asc');這個地址返回是json數據,你直接json_decode()就OK
⑸ JS或PHP實現獲取https協議下上一頁URL
RFC 15.1.3 Encoding Sensitive Information in URI』s 規定:
由HTTPS跳轉到HTTP時不允許發送REFERER頭。
解決方法是把你的網站也成HTTPS的。
參考資料:http://blog.ailms.me/2013/06/24/https-insecure-link-lost-referer-header.html
⑹ PHP怎樣處理HTTPS請求
具體代碼如下:
<?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, '');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>
PHP 獨特的語法混合了C、Java、Perl以及PHP自創的語法。
它可以比CGI或者Perl更快速地執行動態網頁。用PHP做出的動態頁面與其他的編程語言相比,PHP是將程序嵌入到HTML(標准通用標記語言下的一個應用)文檔中去執行,
執行效率比完全生成HTML標記的CGI要高許多;
PHP還可以執行編譯後代碼,編譯可以達到加密和優化代碼運行,使代碼運行更快。
⑺ php 用curl獲取https地址
你就算是
注釋1和注釋2都沒有他照樣會有數據輸出
因為 他默認是輸出你獲得到的數據
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//輸出內容為字元串
你要加上上面這一句話
這樣就不會輸出獲取到的數據
⑻ php獲取https地址
這個應該是wp的代碼吧。。
可以自己用正則匹配替換下,或者直接修改函數都可以
⑼ PHP獲取HTPPS網頁源碼沒有內容怎麼回事
php已提供相關函數。
file_get_contents() 函數把整個文件讀入一個字元串中。
$ret = file_get_contents('要採集的網頁URL');// 若需要從頁面中獲取內容,可以用正則匹配$begin=change_match_string('匹配開頭的字元串');$end=change_match_string('匹配結尾的字元串');$p = "{$begin}(.*){$end}";// 使用正則進行匹配if (eregi($p,$ret,$rs)) return $rs[1];else return false;