1
Im從站點獲取數據www.example.com
。數據表結構類似,還有一個分頁,用於that.im正確獲取第一頁數據並獲取下一頁數據進出口運行我的代碼在forloop
。我知道總沒有頁面,這將是3.My代碼如下: -CURL沒有正確地從站點獲取數據
$url = "http://www.example.com/browseall";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_URL,$url);
$output = curl_exec($ch);
$html = new simple_html_dom();
$html->load_file($url);
foreach($html->find('div.full_listing_pager') as $pages)
{
$page = $pages->children(2)->plaintext;
}
curl_close($ch);
$limit = $page+1;
echo "limit--->".$limit;
echo "<table border=1>";
echo "<tr>";
echo "<th>Listing Id </th>";
echo "<th>Free Km Allowed</th>";
echo "<th>Free Days allowed</th>";
echo "<th>Driver requirements</th>";
echo "<th>Owner comments</th>";
echo "</tr>";
for($i=1;$i<$limit+1;$i++) //$limit =3(no of pages)
{
$url=urlencode('http://www.example.com.au/browseall?browse_filter[from_city]=0&browse_filter[to_city]=0&browse_filter[car]=0&browse_filter[by_date]=0&page='.$i);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
foreach($html->find('table.full_listings_table tbody tr.more_info_second') as $div)
{
$str = "<tr>";
$data = $div->find('td p b',0)->plaintext;
$str .="<td>".$data."</td>";
$data = $div->find('td div b',0)->plaintext;
$str .="<td>".$data."</td>";
$data = $div->find('td br b',0)->plaintext;
$str .="<td>".$data."</td>";
$data = $div->find('td div',0)->plaintext;
$dataLen = strlen($data);
$temp = "Driver requirements:";
$tempLen = strlen($temp);
$pos = strpos($data,$temp,0);
$sum = $pos + $tempLen;
$finalData = substr($data,$sum,$dataLen-$sum);
$str .="<td>".$finalData."</td>";
$data = $div->find('td div',2)->plaintext;
$data = str_replace("Owner comments:"," ",$data);
$str .="<td>".$data."</td>";
echo $str."</tr>";
}
}
echo "</table>";
curl_close($ch);
問題是即時得到第一頁數據的3倍。我想在所有的3個數據table.Is在我的代碼中有什麼問題嗎?請幫助我,IM新到cURL
。
'$ html'定義在哪裏? – 2012-08-02 06:52:08
代碼示例中存在各種錯誤。 '$ html'從哪裏來,它是什麼?從css選擇器來看,你傳遞給find(),你選擇了一個'
代碼編輯請參考 – 2012-08-02 07:00:19
回答
神終於得到了解決......真是即時通訊這樣一個白癡,我寫
$url=urlencode('http://www.example.com.au/browseall?browse_filter[from_city]=0&browse_filter[to_city]=0&browse_filter[car]=0&browse_filter[by_date]=0&page='.$i);
沒有必要使用urlencode.Now通過寫這下面的代碼我得到了我的解決方案: -
來源
2012-08-02 07:20:43
相關問題