php 爬虫 爬取12306接口
来源:互联网 发布:乐云记事关闭 数据怎么 编辑:程序博客网 时间:2024/05/23 14:18
public function actionGet_12306($session,$str){ $url="https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2016-07-05&leftTicketDTO.from_station=BJP&leftTicketDTO.to_station=AKY&purpose_codes=ADULT"; $this->getcurl($url); return $this->renderPartial('index');}public function doget($url){ if(!function_exists('file_get_contents')) { $optionget = array('http' => array('method' => "GET", 'header' => "User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.0.04506; CIBA)\r\nAccept:*/*\r\nReferer:https://kyfw.12306.cn/otn/leftTicket/init")); $file_contents = file_get_contents($url, false , stream_context_create($optionget)); } else { $ch = curl_init(); $timeout = 5; $header = array( 'Accept:*/*', 'Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding:gzip,deflate,sdch', 'Accept-Language:zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4', 'Connection:keep-alive', 'Host:kyfw.12306.cn', 'Referer:https://kyfw.12306.cn/otn/leftTicket/init', ); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER,$header); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 200);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');//如果数据是压缩处理,需要这个参数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回 $file_contents = curl_exec($ch); curl_close($ch); } $file_contents = json_decode($file_contents,true); return $file_contents;}public static function getcurl($url){ $ch=curl_init($url); $header = array( 'Accept:*/*', 'Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding:gzip,deflate,sdch', 'Accept-Language:zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4', 'Connection:keep-alive', 'Host:kyfw.12306.cn', 'Referer:https://kyfw.12306.cn/otn/leftTicket/init', ); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER,$header); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 200);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');//如果数据是压缩处理,需要这个参数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回 $output = curl_exec($ch) ; $json_str=json_decode($output,true); var_dump($output);die; /*return access_token*/ return $json_str;}
0 0
- php 爬虫 爬取12306接口
- PHP爬虫 爬取污染数据实例
- php爬虫:知乎用户数据爬取和分析
- php 爬虫如何爬取ajax异步加载文件
- php爬虫爬取豆瓣电影top250内容
- php简单爬虫使用登录账号密码爬取列表(爬虫二篇)
- 爬虫爬虫学习: 爬取网页图片
- Python爬虫-利用百度地图API接口爬取数据并保存至MySQL数据库
- jsoup爬虫爬取网页
- 爬虫爬取ajax内容
- 爬虫爬取糗事百科
- python爬虫爬取段子
- python爬虫爬取图片
- 爬虫爬取下载图片
- python爬虫爬取网络小说
- 爬虫的定向爬取
- Python 爬虫 爬取视频
- python爬虫爬取csdn
- 【SQL】数据库变为\"SUSPECT\"状态的解决方法
- 致远OA相关修改
- a6精灵切换到首页使用不同浏览器
- Excel-点击单元格,选中单元格开始往下所有不为空的行
- MTD中的nand驱动初步分析---面向u-boot
- php 爬虫 爬取12306接口
- 开启win8的快速启动
- T6 结算成本处理失败
- liunx基础01
- T3 记账提示不能在gl_mpostcond1_pk插入重复键的解决办法
- Service服务的用法
- Windows/Linux下安装python的mysql客户端接口
- opensuse linux开发中用到的一些参考网址
- U8 对账不平案例解析