好了,下面是我對在PHP中,利用捲曲庫:
PHP絕不認爲合適的任務。然而,在語言中設置你要找的東西很容易。
<?php
error_reporting(-1);
$ch = curl_init();
/*Some sites block your access if you do not have cookies enabled. In order to get the cookies you will need to submit the form manually and using a packet sniffer (or Firebug) get the cookies that are being sent.*/
//$cookies ="CFID=25318504; CFTOKEN=38400766; PERSON_ID=3461047";
/*Again, if you have Firebug then getting the following POST data, once you submit the form manually, fairly straightforward. This is what cURL will utilize in the POST fields*/
//The action=submit may also vary, this is also easily acceible via Firebug. (right next to the parameters tab.
$post_data = "username=test&password=test&action=submit";
curl_setopt($ch, CURLOPT_URL, "http://www.sitename.com");
//follows a Location: redirect
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//send above cookies, which were gathered manually =(
//Utilize this only if cookies are a neccesity.
//curl_setopt($ch, CURLOPT_COOKIE, $cookies);
//Doing a POST request
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
if($output == false) {
echo "cURL Error:" . curl_error($ch);
}
//You can sort this data using an HTML parser
echo $output;
一旦您已成功連接到該網站,你可以利用許多PHP HTML解析器之一通過數據,如穿越:DOM文檔和XPath和SimpleXML的。
我不認爲這個問題可以以目前的形式回答。 – ChaosPandion 2010-09-23 23:14:01
可能太寬泛。你建議我添加什麼? – Qcom 2010-09-23 23:16:07
是的,當然,這是可能的。我會花時間學習一門新的語言,開發腳本,反覆試驗,最後實現,而不是學校。另外,我不確定你的學校會如何感覺你在他們的網站上運行腳本,他們可能會在故意發現後故意破壞你的腳本。 – Robert 2010-09-23 23:16:41