zoukankan      html  css  js  c++  java
  • 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;
    ?>
  • 相关阅读:
    2016012061 小学四则运算练习软件项目报告
    阅读《构建之法》的几点思考
    软件工程之我见
    作业五
    结对作业
    第4.17章读书笔记
    week_2 四则运算
    第1.2.16章读书笔记
    我与软件工程
    团队项目Alpha冲刺阶段之学习总结
  • 原文地址:https://www.cnblogs.com/csjoz/p/7244115.html
Copyright © 2011-2022 走看看