csjoz11

导航

curl

_____________获取淘宝标题
<?php header("Content-type: text/html; charset=utf-8"); $url = 'https://item.taobao.com/item.htm?spm=a219r.lm5704.14.15.Cb4K9H&id=534410524947&ns=1&abbucket=7#detail'; echo getTitle($url); function getTitle($url){ // $header = array('user-agent:'.$_SERVER['HTTP_USER_AGENT']); $data = curl_https($url); preg_match('/<title>(.*)<\/title>/', $data, $matches); return $matches[1]; } /** curl 获取 https 请求 * @param String $url 请求的url * @param Array $data 要發送的數據 * @param Array $header 请求时发送的header * @param int $timeout 超时时间,默认30s */ function curl_https($url, $data=array(), $header=array(), $timeout=30){ $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //curl_setopt($ch, CURLOPT_POST, true); //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); $response = curl_exec($ch); if($error=curl_error($ch)){ die($error); } curl_close($ch); return $response; }
 
_____________________________
 
<?php
 
 
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.php100.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=csjoz11&pwpwd=asasas';
 
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
 
 
$url='http://bbs.php100.com/read.php?tid-35479.html';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<a href=\"userpay.php\" class=\"mr10\">(\d*?)\s.*?<\/a>/",$contents,$arr);
 
curl_close($ch);
var_dump($arr);
exit;
?>

posted on 2017-07-27 11:56  csjoz11  阅读(137)  评论(0编辑  收藏  举报