-1
我刮这个网址,因为它是我最后一年的项目,但这段代码只报废1页的搜索查询我希望分页(如1,2,3,4,5)最后请帮助PHP网络抓取HTMLDOM分页
我已经实现了一个使用CURL获取数据的数据抓取脚本。
但是,抓取记录只有一个页面,但我想要所有的数据,因为在那个页面分页。
<form action="" method="post" class="form-horizontal" id="home-search">
<input type="text" name="keyword" id="keyword">
<input type="submit">
</form>
<?php
if(isset($_POST['keyword'])){
$keyword = urlencode($_POST['keyword']);
ini_set('display_errors', 1);
ini_set('max_execution_time', 300);
$html = file_get_contents('https://www.bestjobs.co.za/jobs/?q='.$keyword);
//echo $html;
$indeedDotPk = array();
//$html = file_get_contents($result);
libxml_use_internal_errors(true);
$doc = new DOMDocument;
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$node = $xpath->query('//div[@class="paginas"]/ul/li/a/@href');
$total_pages = 0;
$start = 0;
$job_title_index = 0;
$job_link_index = 0;
$job_description_index = 0;
$job_experience_index = 0;
foreach ($node as $key => $value) {
$total_pages++;
// echo $value->textContent;
// echo "<br>";
// echo "<br>";
// echo "<br>";
}
for ($i=0; $i < $total_pages; $i++) {
ini_set('max_execution_time', 300);
$html = file_get_contents('https://www.bestjobs.co.za/jobs/?q='.$keyword.'&start='.$start);
libxml_use_internal_errors(true);
$doc = new DOMDocument;
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
// Job Description
$node = $xpath->query('//a[@class="js-o-link"]');
foreach ($node as $key => $value) {
if(is_string($value->textContent)){
$indeedDotPk[$job_description_index++]['job_description'] = $value->textContent;
}
}
// Job Description
$start = $start + 10;
}
foreach ($indeedDotPk as $key => $value) {
if(!empty($value['job_description'])){
?>
<table border="1">
<tr >
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<?php echo $value['job_description']?>
</td>
</tr>
有没有人有一个想法,我怎么能像1,2,3,4,5一样设置分页?
如果有人有任何建议,那么请帮助我。
谢谢...
我didnot得到它Nitin先生基本上我是学生和begineer你可以modiefy我的上面的代码,告诉我怎么做,这将是一个很大的帮助 –