每日自動抓取搜狐廣告聯盟昨日收益,避免人工登錄。難點:驗證碼無法自動識別。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://union.sogou.com/validateCode");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); // 保存Cookies
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$img = curl_exec($ch);
header("Content-type: image/gif");
echo $img;
$post = array(
'loginFromPage' => 'homePage',
'username' => 'xxxx',
'password' => 'xxxx',
'activecode' => $_POST['code'], // 人工輸入
'button.x' => 14, 'button.y' => 16
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); // 攜帶Cookies
$response = curl_exec($ch);
$dom = str_get_html($response);
$text = $dom->find('div.rtable table tbody tr', 1)->plaintext;
$data = preg_split("/\s+/", $text);
// 提取 money, shows, times 寫入數據庫