⑴ 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;