1. <?php
  2. $hotel = new curl(false,0);
  3. $str = $hotel -> post("http://www.todayinns.com/login.php?do=login",array("Referer"=>"","username"=>"18612690317","password"=>"2010"))->execute();
  4. echo $hotel -> get("http://www.todayinns.com/my_jf.php")->execute();;
  5.  
  6. /**
  7. * 一个基础的CURL类
  8. *
  9. * @author Smala
  10. */
  11. class curl{
  12. public $ch;
  13. public $cookie = '/cookie';
  14. public $rstr;
  15. public $info;
  16.  
  17. public function __construct($ssl=true,$cookieName="tmp.cookie"){
  18.  
  19. $this -> cookie = dirname(__FILE__)."/".$cookieName;
  20. $this -> ch = curl_init();
  21. curl_setopt($this -> ch ,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36');//设置用户代理
  22. curl_setopt($this -> ch,CURLOPT_COOKIEJAR,$this -> cookie);
  23. curl_setopt($this -> ch,CURLOPT_COOKIEFILE,$this -> cookie);
  24.  
  25. if($ssl){
  26. curl_setopt($this -> ch, CURLOPT_SSL_VERIFYPEER, false);
  27. curl_setopt($this -> ch, CURLOPT_SSL_VERIFYHOST, false);
  28. }
  29. curl_setopt($this -> ch,CURLOPT_RETURNTRANSFER,1);
  30. }
  31.  
  32. public function set($opt){
  33. foreach($opt as $key => $value)
  34. curl_setopt($this -> ch,$key,$value);
  35. return $this;
  36. }
  37. public function get($url,$data=array()){
  38. $queryString = http_build_query($data);
  39. if(!empty($queryString)){
  40. $url.= '?'.$queryString;
  41. }
  42. curl_setopt($this -> ch,CURLOPT_URL,$url);
  43. return $this;
  44.  
  45. }
  46. public function setHeader($data=array()){
  47. curl_setopt($this -> ch,CURLOPT_HTTPHEADER,$data);
  48. return $this;
  49. }
  50. public function post($url,$data = array()){
  51. $post = '';
  52. foreach($data as $key=>$value){
  53. $post .= $key.'='.$value."&";
  54.  
  55. }
  56. $post = trim($post,'&');
  57. curl_setopt($this -> ch,CURLOPT_URL,$url);
  58. curl_setopt($this -> ch,CURLOPT_POST,1);
  59. curl_setopt($this -> ch,CURLOPT_POSTFIELDS,$post);
  60. return $this;
  61. }
  62. public function execute($close=true){
  63.  
  64. $this -> rstr = curl_exec($this -> ch);
  65. $this -> info = curl_getinfo($this -> ch);
  66. if($close){
  67. // curl_close($this -> ch);
  68. }
  69. return $this -> rstr;
  70.  
  71. }
  72. public function close(){
  73. curl_close($this -> ch);
  74. }
  75.  
  76. }
  1. $hotel = new curl(false,0);
  2. $str = $hotel -> post("http://www.todayinns.com/login.php?do=login",array("Referer"=>"","username"=>$_COOKIE['the_tel'],"password"=>$_COOKIE['password']))->execute();
  3. $arrs = $hotel -> get("http://www.todayinns.com/my_ticket.php")->execute();
  4. preg_match_all('/<dd class="c">(.*?)<\/dd>/is',$arrs,$tmp);
  5. preg_match_all( '/<tr[^>]*([\s\S]*?)<\/tr>/i', $tmp[1][0], $arr );
  6. preg_match_all( '/<td>(.*?)<\/td>/i', $arr[1][1], $volume );

curl抓取信息的更多相关文章

  1. 调用 CURL 使用正则抓取信息

    Class MyCurl{  protected $_pdo;     //构造方法 链接数据库  public function __construct(){      $this->_pdo ...

  2. php多线程抓取信息测试例子

    php多线程抓取信息测试例子 PHP 5.3 以上版本,使用pthreads PHP扩展,可以使PHP真正地支持多线程.多线程在处理重复性的循环任务,能够大大缩短程序执行时间. PHP扩展下载:htt ...

  3. PHP使用CURL抓取网页

    CURL是一个非常强大的开源库,支持很多协议,包括HTTP.FTP.TELNET等,我们使用它来发送HTTP请求.它给我 们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数,并且支持HTTPS ...

  4. PHP CURL 抓取失败 自己调试

    蛋疼的一下午,物理机win7旗舰版+APACHE2 ,CURL抓取一直成功. 虚拟机ubuntu+apache2一直抓取失败. 晚上,问个仁兄才知道,CURL可以调试: 参考这位兄台: 地址 curl ...

  5. shell用curl抓取页面乱码,参考一下2方面(转)

    1.是用curl抓取的数据是用类似gzip压缩后的数据导致的乱码.乱码:curl www.1ting.com |more乱码:curl -H "Accept-Encoding: gzip&q ...

  6. PHP cURL抓取网上图片

    cURL的底层是由一个命令行工具实现的,用于获取远程文件或传输文件,更多的情况是用来模拟get/post表单提交.也可以用户文件上传,爬取文件,支持FTP/FTPS,HTTP/HTTPS等协议,通俗来 ...

  7. java练习题(字符串类):显示4位验证码、输出年月日、从XML中抓取信息

    1.显示4位验证码 注:大小写字母.数字混合 public static void main(String[] args) { String s="abcdefghijklmnopqrstu ...

  8. php curl抓取远程页面内容的代码

    使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...

  9. 使用file_get_contents()和curl()抓取网络资源的效率对比

    使用file_get_contents()和curl()抓取网络资源的效率对比 在将小程序用户头像合成海报的时候,用到了抓取用户头像对应的网络资源,那么抓取方式有很多,比如 file_get_cont ...

随机推荐

  1. 一条带分页的sql

    SELECT * FROM (SELECT USERID, TYPE, TYPE_DESC, SEX, USERNAME, HEADPORTRAIT, HOSPITAL, HLEVEL, DEPT, ...

  2. SqlMapConfig.xml全局配置文件解析

    一:SqlMapConfig.xml配置文件的内容和配置顺序如下 properties(属性) settings(全局配置参数) typeAiases(类型别名) typeHandlers(类型处理器 ...

  3. Shell continue循环

    [oracle@june ~]$ cat continue.sh for i in a b c d e f g do if [ "$i" = "c" ] the ...

  4. codevs1906 最长递增子序列问题

    题目描述 Description 给定正整数序列x1,..... , xn  .(1)计算其最长递增子序列的长度s.(2)计算从给定的序列中最多可取出多少个长度为s的递增子序列.(3)如果允许在取出的 ...

  5. hdu1693:eat trees(插头dp)

    题目大意: 题目背景竟然是dota!屠夫打到大后期就没用了,,只能去吃树! 给一个n*m的地图,有些格子是不可到达的,要把所有可到达的格子的树都吃完,并且要走回路,求方案数 题解: 这题大概是最简单的 ...

  6. HDU-5504(逻辑if-else大水题)

    Problem Description You are given a sequence of N integers. You should choose some numbers(at least ...

  7. [每日一题] OCP1z0-047 :2013-08-05 SELECT语句――列的表达式

    按题意操作如下: hr@MYDB> SELECT first_name,salary,salary*12+salary*12*0.5 "ANNUAL SALARY + BONUS&qu ...

  8. 使用GULP打包、压缩与打版本号

    这篇文章讲我整理的一种打包项目的方式,以下是我的依赖清单 "devDependencies": { "gulp": "^3.9.1", &q ...

  9. JSP入门:介绍什么是JSP和Servlet(转)

    转自:http://developer.51cto.com/art/200907/134506.htm JSP入门:什么是jsp? JSP(Java Server Pages)是由Sun Micros ...

  10. (原)Apache添加完限速模块后的文件

    点我下载 解压后得到apache2文件夹和readme.txt文本 按照readme.txt修改apache2文件夹.