我想寫一個刮刮臉的應用程序,我遇到了問題。我的PHP Curl代碼不會以書籍的價格拉動頁面。它將我返回到域的Web根目錄。刮書價格
我在努力按ISBN搜索網站。
我一直在撞牆撞牆。任何幫助將不勝感激!
代碼:
<form method="post" for="new-search" name="SearchTerm" class='form-validate' id="SearchTerm" action="index.php">
<textarea rows="3" name="SearchTerm" id="SearchTerm" cols="40" class="validate-required error"></textarea><div class="error" id="SearchTerm-error">
<br>
<button class="search primary" type="submit">continue</button>
</form>
<?php
/*
echo("<pre>");print_r($_GET);echo("</pre>");
echo("<pre>");print_r($_POST);echo("</pre>");
*/
$isbn = $_POST['SearchTerm'];
$userAgent = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16';
$fields = array(
'url' => ("http://www.bookleberry.com/Search/SearchKeyword"),
'qurl' => ("http://www.bookleberry.com/Search/SearchKeyword/" . $_POST['SearchTerm']),
'SearchTerm' => ($_POST['SearchTerm']),
'Page' => ('1'),
'class' => ('textfield validate-required'),
'for' => ('new-search'),
'result-count' => ('1'),
'status' => 'success',
);
$SearchTerm = ($fields['SearchTerm']);
$url = ($fields['url']);
$Page = ($fields['Page']);
echo("<pre>");
print_r($fields);
echo("</pre>");
if ($isbn != NULL){
//open connection
$ch = curl_init($url);
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_HEADER, $userAgent);
curl_setopt($ch, CURLOPT_URL, $url);
echo "before curl_exec:<br>";
echo "curl_errno=". curl_errno($ch) ."<br>";
echo "curl_error=". curl_error($ch) ."<br>";
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "?SearchTerm=$SearchTerm");
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 9999999);
curl_setopt($ch,CURLOPT_HTTPHEADER,array (
"Accept: application/json"
));
$info = curl_getinfo($ch);
//execute post
$result = curl_exec($ch);
print $result;
print "<pre>\n";
print_r(curl_getinfo($ch)); // get error info
?>
副手我會說,因爲內容似乎是AJAX填充。用PHP/CURL刮不會讓你走得太遠,你需要攔截AJAX調用,並獲得javascript在後臺使用的結果。 – 2011-02-24 19:22:06