国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP實現登錄搜狐廣告獲取廣告聯盟數據的方法【附demo源碼】

2024-05-04 23:51:05
字體:
來源:轉載
供稿:網友

本文實例講述了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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 江山市| 两当县| 雅安市| 准格尔旗| 白沙| 通辽市| 明星| 抚远县| 离岛区| 通辽市| 大埔县| 巢湖市| 柯坪县| 定远县| 三穗县| 灯塔市| 禄丰县| 兖州市| 察哈| 安新县| 漳州市| 安溪县| 西乌珠穆沁旗| 陇西县| 平凉市| 镇坪县| 萨迦县| 临夏市| 北流市| 尤溪县| 台前县| 凌海市| 苍南县| 额济纳旗| 扎赉特旗| 新田县| 泸溪县| 佛冈县| 德庆县| 林州市| 安岳县|