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 ...
随机推荐
- iOS-OC命名规范
IOS开发(OC)中的命名规范 正文:通过读写大量代码我有自己的一套编程思路和习惯,自认为自己的编码习惯还是不错的,代码结构也算清晰,因为我一直以来都是代码看的多写的多,但是总结的比较少,知识经常不成 ...
- ural 1126 Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126 #include <cstdio> #include <cstring&g ...
- Inno Setup for Windows service
Inno Setup for Windows service? up vote86down votefavorite 77 I have a .Net Windows service. I want ...
- 创建Windows服务(Windows Services)N种方式总结
最近由于工作需要,写了一些windows服务程序,有一些经验,我现在总结写出来.目前我知道的创建创建Windows服务有3种方式:a.利用.net框架类ServiceBaseb.利用组件Topshel ...
- 32G sd卡格式化成fat
fat文件系统格式只支持4G及以下的内存空间的存储设备,对于4G及以上的存储设备可以使用fat32或ntfs文件系统,建议使用ntfs文件系统,这样可以最有效地利用存储设备的存储空间,而且可以减少出现 ...
- Stooge排序
又叫臭皮匠排序... 在<算法导论>作为反例出现的漂亮但极其低效的排序算法. 基本思路是:只要数组长度大于3,先将头与尾排序,然后递归调用排序前三分之二,再递归调用排序后三分之二,最后再递 ...
- 翻译brent ozar的sqlserver dba训练课程——第一章:建立数据库服务器清单
在公司里,走进销售副总裁的办公室,询问他手下有多少销售人员.不,我的意思是你并不要那么做,他们会问你销售工具为什么那么慢. 其实我的意思是,如果你能走进他的办公室问他这个问题.我敢打赌,他会马上回答 ...
- socket实现局域网通信
今天实现了一个局域网通信的小例子,上来记录一下,代码不成熟,勿拍. 这是我本机客户端: 这是我虚拟机的客户端. 我为他们分配了静态IP,这样就可以实现局域网通信了.注意代码中必须把监视线程的IsBac ...
- [深入React] 5.MVC
react 是一种典型的MVC框架. 在jquery中,我们都是针对dom编程,由dom事件触发dom改变,MVC三层代码混在一起. 比如点击变颜色 $('#btn').click(function( ...
- DB2高级安装
学习从安装开始,哈哈.这里记下 Windows 和 UNIX/Linux安装DB2的各种方式,不同,及具体的一些细节. Windows下向导化安装: setup.exe ...