php 爬虫 (爬取小说搜索)
in PHPer技术 with 0 comment

php 爬虫 (爬取小说搜索)

in PHPer技术 with 0 comment

基于 simple_html_dom 实现。
中文手册:https://microphp.us/plugins/public/microphp_res/simple_html_dom/manual.htm
下载地址:https://sourceforge.net/projects/simplehtmldom/
另外推荐一个框架:http://www.querylist.cc/#one

基于simple_html_dom 类 的代码示例:


require_once './simp/simple_html_dom.php';
$url = "https://www.bimo.cc";
$name = $_POST['keyword']; //搜索关键字 
$html= file_get_html($url . "/search.aspx?keyword={$name}");

 
foreach($html->find('.result-game-item') as $k=>$element){
    $data[$k]['title']   = $element->find('.result-game-item-title-link', 0)->plaintext; //小说名字

    $data[$k]['src']   = $element->find('.result-game-item-pic img', 0)->src; //图片
    $data[$k]['desc']   = $element->find('.result-game-item-desc', 0)->plaintext; //详情
    $data[$k]['author']   = $element->find('.result-game-item-info-tag span', 1)->plaintext; //作者
    $data[$k]['href'] = $element->find('.result-game-item-pic-link', 0)->href;//内页
 

}
$data_arr['data'] = $data;
if(empty($data)){
    $data_arr['code'] = 4000;
}else{
    $data_arr['code'] = 2000;
}

echo json_encode($data_arr);


效果图:

微信图片_20190610182749.png

Responses