php爬蟲 phpspider


<?php
/**
 * Created by PhpStorm.
 * User: brady
 * Date: 2016/12/9
 * Time: 17:32
 */
ini_set("memory_limit", "1024M");
require dirname(__FILE__).'/../core/init.php';

$url = "http://www.epooll.com/archives/806/";
$html = requests::get($url);
// 抽取文章標題
$selector = "//*[@id=\"content\"]/div[1]/div[1]/h1/a";

$title = selector::select($html, $selector);
// 檢查是否抽取到標題
// 抽取文章作者
$selector = "//*[@id=\"content\"]/div[1]/div[1]/h6/span[1]";
$author = selector::select($html, $selector);
// 檢查是否抽取到作者
// 去掉 作者:
$author = str_replace("作者:", "", $author);
//發布時間
$selector = "//*[@id=\"content\"]/div[1]/div[1]/h6/span[2]";
$time = selector::select($html, $selector);
$time = str_replace("發布時間:",'', $time);
$time  = date("Y-m-d H:i:s",strtotime($time));
// 抽取文章內容
$selector = "//*[@id=\"content\"]/div[1]/div[2]";
$content = selector::select($html, $selector);
// 檢查是否抽取到內容
$data = array(
    'article_title' => $title,
    'article_author' => $author,
    'article_content' => $content,
);
// 查看數據是否正常
$res = db::insert("content", $data);
var_dump($res);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM