侯体宗的博客
  • 首页
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

PHP实现登录搜狐广告获取广告联盟数据的方法【附demo源码】

php  /  管理员 发布于 8年前   155

本文实例讲述了PHP实现登录搜狐广告获取广告联盟数据的方法。分享给大家供大家参考,具体如下:

一直有一个想法,每次都要登录去看联盟昨天收益多少?每天都要登录和麻烦,能不能做一个汇总发邮件的功能呢?

可惜了,验证码绕不过去,只能想一个办法。先在服务器手动打一次验证码,然后在通过定时器,每隔10分钟请求一个页面

这样的话Cookies就不会失效,,然后每周只需要跟我汇总数据就Ok了。。

远程提交表单的原理,可以参考:PHP基于curl后台远程登录正方教务系统的方法

参考的代码还是一样的如下

获取验证码Code.php

define("SITE_PATH", $_SERVER['DOCUMENT_ROOT']); $LoginUrl = "http://union.sogou.com/"; $url = $LoginUrl."validateCode"; $filedir = SITE_PATH."/TMP/Cookies"; $cookie_file = $filedir."/cookie.txt"; if(!mkdirs($filedir)) { echo "目录创建失败";  exit; }$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header部分 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); //curl_setopt($ch, CURLOPT_REFERER, "http://125.89.69.234"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, "10"); $response = curl_exec($ch); curl_close($ch); header("Content-type:image/gif"); echo $response; //创建目录 function mkdirs($dir) {   if(!is_dir($dir))  {   if(!mkdirs(dirname($dir))){    return false;   }   if(!mkdir($dir,0777)){    return false; } }  return true;}

获取数据的页面,这里需要通过表单来提交手动的验证码

define("SITE_PATH", $_SERVER['DOCUMENT_ROOT']);require_once SITE_PATH.'/class/SimpleHtmlDom.class.php';class GetData{private $url ;public function __construct(){$this->url = "http://union.sogou.com/index.action?searchBean.timeSegment=yestoday";$this->LoginUrl = "http://union.sogou.com/";$this->PostData = $this->LoginUrl."loginauth.action";$this->table = "dwz_union";}public function post($code){$POST['loginFromPage'] = "homePage";$POST['username'] = "xxxxxx";$POST['password'] = "xxxxx";$POST['activecode'] = $code;$POST['button.x']="14";$POST['button.y']="16";foreach($POST as $key=>$value){$tmp[] = $key."=".$value;}$postStr = implode("&", $tmp);$filedir = SITE_PATH."/TMP/Cookies";$cookie_file = $filedir."/cookie.txt";$result = $this->curl($this->PostData, "http://union.sogou.com/loginauth.action", $postStr, $cookie_file);$url = "http://union.sogou.com/index.action";$postArr = "searchBean.timeSegment=yestoday";$response = $this->curl($url, " http://union.sogou.com/index.action?pid=dengwz7788", $postArr, $cookie_file);$this->saveData($response);}private function saveData($response){$dom = str_get_html($response);$tmp = $dom->find('div.rtable table tbody tr',1)->plaintext;$data = preg_split("/\s+/i", $tmp);$this->link();$date = date('Y-m-d',strtotime('-1 day'));$datetime = date('Y-m-d H:i:s');$money = $data['4'];$shows = $data['2'];$times = $data['3'];$sql = "select sum(money) as total from {$this->table}";$query = mysql_query($sql);$totaTmp = mysql_fetch_row($query);var_dump($totalTmp);if(empty($totaTmp['0'])){$total = $money;}else{$total = $totaTmp['0']+$money;}$sql = "insert into {$this->table}(date,datetime,money,shows,times,total) values('{$date}','{$datetime}','{$money}','{$shows}','{$times}','{$total}')";mysql_query($sql);}private function link(){$link = mysql_connect('localhost', 'root', '');mysql_select_db('dblog', $link);mysql_query('SET NAMES utf8');}private function saveHtml($infomation,$filedir,$filename){if(!$this->mkdirs($filedir)){return 0;}$sf = $filedir."/".$filename;$fp=fopen($sf,"w"); //写方式打开文件fwrite($fp,$infomation); //存入内容fclose($fp); //关闭文件}//创建目录private function mkdirs($dir){if(!is_dir($dir)){if(!$this->mkdirs(dirname($dir))){return false;}if(!mkdir($dir,0777)){return false;}}return true;}public function login(){$filedir = SITE_PATH."/TMP/Cookies";if(!$this->mkdirs($filedir)){echo "目录创建失败";exit;}$cookie_file = $filedir."/cookie.txt";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $this->LoginUrl);curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header部分curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);//curl_setopt($ch, CURLOPT_REFERER, "http://125.89.69.234");curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_TIMEOUT, "10");$response = curl_exec($ch);curl_close($ch);// 抽CURL浼璇}private function curl($url,$url2,$fields,$cookie_file){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header部分curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: union.sogou.com" ));curl_setopt($ch, CURLOPT_REFERER,$url2);$response = curl_exec($ch);//echo curl_error($ch);curl_close($ch);return $response;}}$GetData = new GetData();if(isset($_POST['code'])){$GetData->POST($_POST['code']);}

完整实例代码点击此处本站下载。

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《PHP数学运算技巧总结》、《php正则表达式用法总结》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • PHP基于curl后台远程登录正方教务系统的方法
  • php 使用curl模拟登录人人(校内)网的简单实例
  • PHP Curl模拟登录微信公众平台、新浪微博实例代码
  • PHP curl模拟登录带验证码的网站
  • PHP使用CURL模拟登录的方法
  • PHP读取CURL模拟登录时生成Cookie文件的方法
  • PHP使用CURL实现对带有验证码的网站进行模拟登录的方法
  • PHP中使用CURL模拟登录并获取数据实例
  • PHP CURL获取cookies模拟登录的方法
  • php使用curl模拟登录后采集页面的例子
  • PHP CURL模拟登录新浪微博抓取页面内容 基于EaglePHP框架开发


  • 上一条:
    基于php判断客户端类型
    下一条:
    php生成与读取excel文件
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在go语言中实现字符串可逆性压缩及解压缩功能(0个评论)
    • 使用go + gin + jwt + qrcode实现网站生成登录二维码在app中扫码登录功能(0个评论)
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客