我試圖通過cURL從通過登錄頁面的網站獲取收入。我知道這是一個馬虎的方式,但我別無選擇。使用PHP cURL從網站獲取收入
<?php
$username = "example";
$password = "example";
$postfields = "email=$username&password=$password";
// Use Curl to return the raw source of a webpage to a variable called
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HEADER, 1); // Get the header
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/login");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");
$page = curl_exec($ch);
curl_close($ch); // Closing
if (preg_match("/<th>(.*)<\/th/s", $page, $matches)) {
echo $matches[1];
}
?>
基本上我能闖過登錄罰款,當試圖使用的preg_match不搶任何東西它重定向我到特定的網站,我想抓住從收入的儀表盤,但是,它只是打印儀表板的所有HTML。
我想只得到 「$ 99.99」 的
<th>$99.99</th>
幫助極大的讚賞之內。
這樣做。謝謝! – Ziygo 2012-03-04 22:42:54