curl抓取信息
<?php
$hotel = new curl(false,0);
$str = $hotel -> post("http://www.todayinns.com/login.php?do=login",array("Referer"=>"","username"=>"18612690317","password"=>"2010"))->execute();
echo $hotel -> get("http://www.todayinns.com/my_jf.php")->execute();; /**
* 一个基础的CURL类
*
* @author Smala
*/
class curl{
public $ch;
public $cookie = '/cookie';
public $rstr;
public $info; public function __construct($ssl=true,$cookieName="tmp.cookie"){ $this -> cookie = dirname(__FILE__)."/".$cookieName;
$this -> ch = curl_init();
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');//设置用户代理
curl_setopt($this -> ch,CURLOPT_COOKIEJAR,$this -> cookie);
curl_setopt($this -> ch,CURLOPT_COOKIEFILE,$this -> cookie); if($ssl){
curl_setopt($this -> ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this -> ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($this -> ch,CURLOPT_RETURNTRANSFER,1);
} public function set($opt){
foreach($opt as $key => $value)
curl_setopt($this -> ch,$key,$value);
return $this;
}
public function get($url,$data=array()){
$queryString = http_build_query($data);
if(!empty($queryString)){
$url.= '?'.$queryString;
}
curl_setopt($this -> ch,CURLOPT_URL,$url);
return $this; }
public function setHeader($data=array()){
curl_setopt($this -> ch,CURLOPT_HTTPHEADER,$data);
return $this;
}
public function post($url,$data = array()){
$post = '';
foreach($data as $key=>$value){
$post .= $key.'='.$value."&"; }
$post = trim($post,'&');
curl_setopt($this -> ch,CURLOPT_URL,$url);
curl_setopt($this -> ch,CURLOPT_POST,1);
curl_setopt($this -> ch,CURLOPT_POSTFIELDS,$post);
return $this;
}
public function execute($close=true){ $this -> rstr = curl_exec($this -> ch);
$this -> info = curl_getinfo($this -> ch);
if($close){
// curl_close($this -> ch);
}
return $this -> rstr; }
public function close(){
curl_close($this -> ch);
} }
$hotel = new curl(false,0);
$str = $hotel -> post("http://www.todayinns.com/login.php?do=login",array("Referer"=>"","username"=>$_COOKIE['the_tel'],"password"=>$_COOKIE['password']))->execute();
$arrs = $hotel -> get("http://www.todayinns.com/my_ticket.php")->execute();
preg_match_all('/<dd class="c">(.*?)<\/dd>/is',$arrs,$tmp);
preg_match_all( '/<tr[^>]*([\s\S]*?)<\/tr>/i', $tmp[1][0], $arr );
preg_match_all( '/<td>(.*?)<\/td>/i', $arr[1][1], $volume );
curl抓取信息的更多相关文章
- 调用 CURL 使用正则抓取信息
Class MyCurl{ protected $_pdo; //构造方法 链接数据库 public function __construct(){ $this->_pdo ...
- php多线程抓取信息测试例子
php多线程抓取信息测试例子 PHP 5.3 以上版本,使用pthreads PHP扩展,可以使PHP真正地支持多线程.多线程在处理重复性的循环任务,能够大大缩短程序执行时间. PHP扩展下载:htt ...
- PHP使用CURL抓取网页
CURL是一个非常强大的开源库,支持很多协议,包括HTTP.FTP.TELNET等,我们使用它来发送HTTP请求.它给我 们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数,并且支持HTTPS ...
- PHP CURL 抓取失败 自己调试
蛋疼的一下午,物理机win7旗舰版+APACHE2 ,CURL抓取一直成功. 虚拟机ubuntu+apache2一直抓取失败. 晚上,问个仁兄才知道,CURL可以调试: 参考这位兄台: 地址 curl ...
- shell用curl抓取页面乱码,参考一下2方面(转)
1.是用curl抓取的数据是用类似gzip压缩后的数据导致的乱码.乱码:curl www.1ting.com |more乱码:curl -H "Accept-Encoding: gzip&q ...
- PHP cURL抓取网上图片
cURL的底层是由一个命令行工具实现的,用于获取远程文件或传输文件,更多的情况是用来模拟get/post表单提交.也可以用户文件上传,爬取文件,支持FTP/FTPS,HTTP/HTTPS等协议,通俗来 ...
- java练习题(字符串类):显示4位验证码、输出年月日、从XML中抓取信息
1.显示4位验证码 注:大小写字母.数字混合 public static void main(String[] args) { String s="abcdefghijklmnopqrstu ...
- php curl抓取远程页面内容的代码
使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...
- 使用file_get_contents()和curl()抓取网络资源的效率对比
使用file_get_contents()和curl()抓取网络资源的效率对比 在将小程序用户头像合成海报的时候,用到了抓取用户头像对应的网络资源,那么抓取方式有很多,比如 file_get_cont ...
随机推荐
- [LeetCode 119] - 杨辉三角形II(Pascal's Triangle II)
问题 给出一个索引k,返回杨辉三角形的第k行. 例如,给出k = 3,返回[1, 3, 3, 1] 注意: 你可以优化你的算法使之只使用O(k)的额外空间吗? 初始思路 首先来复习复习杨辉三角形的性质 ...
- java疯狂演义----简单java IDE工具
file:commons package org.crazyit.editor.commons; import org.crazyit.editor.EditorFrame; import org.c ...
- 如何统一修改 Altium Designer 中的字符大小
如下图 1 所示: Q1. Q2. C1. C2. R1 等等的字符你想统一修改他们的大小.原来是 Text Height( 100mil), Text Width( 12mil),想改成 Text ...
- Linux read语法及浅析
read命令 -n(不换行) -p(提示语句) -n(字符个数) -t(等待时间) -s(不回显) 1.基本读取read命令接收标准输入(键盘)的输入,或其他文件描述符的输入(后面在说).得到输入后, ...
- 基于SQL_ID查看对象大小
SQL> set echo off set echo off set verify off set serveroutput on set feedback off set lines 200 ...
- css属性之appearance
appearance 属性允许您使元素看上去像标准的用户界面元素. 案例: 使 div 元素看上去像一个按钮 <!DOCTYPE html> <html> <head&g ...
- sql语句相关操作
create user test identified by test default tablespace users temporary tablespace temp quota 3M on u ...
- Nmon 监控 Linux 的系统性能
Nmon(得名于 Nigel 的监控器)是IBM的员工 Nigel Griffiths 为 AIX 和 Linux 系统开发的一款计算机性能系统监控工具.Nmon 可以把操作系统的统计数据展示在屏幕上 ...
- 深入理解linux网络技术内幕读书笔记(十)--帧的接收
Table of Contents 1 概述 1.1 帧接收的中断处理 2 设备的开启与关闭 3 队列 4 通知内核帧已接收:NAPI和netif_rx 4.1 NAPI简介 4.1.1 NAPI优点 ...
- WingIDE注册破解方法
WingIDE是Python程序语言设计的集成开发环境,具有语法标签高亮显示,命令自动完成和函数跳转列表等非常强大的功能.本文主要介绍WingIDE 5安装及注册破解方法. 1. WingIDE 5下 ...