實戰使用QueryListPHP框架采集AE博客文章

介紹

本次為大家帶來QueryListPHP框架的深度用法
采集內容有

  • 文章標題
  • 文章鏈接
  • 發布作者
  • 發布時間
  • 下載鏈接(自動獲取下載鏈接通道及名字)
  • 文章ID(用來做是否重複判斷)
  • 自動圖片轉MD語法

實現代碼

use QL\QueryList;

$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'http://www.aeink.com');
$html = (string)$res->getBody();
$title = QueryList::html($html)->find('.excerpt')->map(function ($Row) {
    global $client;
    $href = $Row->find("header>h2>a")->attr("href");
    preg_match('/www.aeink.com\/(\d+)/', $href, $matches);
    $id = $matches[1];
    $title = $Row->find("header>h2>a")->text();
    $res = $client->request('GET', $href);
    $html = (string)$res->getBody();
    $date = str_replace("日期:", "", QueryList::html($html)->find(".article-meta>span:first")->text());
    $author = QueryList::html($html)->find(".article-meta span:eq(1)")->text();
    $article_content = QueryList::html($html)->find(".article-content");
    $down = $article_content->find("#down-tipid>strong a")->attr("href");
    $article_content->find('.paydown,.post-copyright')->remove();
    $content = $article_content->html();
    $details = preg_replace_callback('/<img.*?src="(.*?)".*?>/is', function ($text) {
        global $title;
        return "\n" . '![' . $title . '](' . $text[1] . ')' . "\n";
    }, $content);
    $details = preg_replace_callback('/<style>(.*?)<\/style>/is', function ($text) {
        return "";
    }, $details);
    $text = QueryList::html($details)->find("")->text();
    $res = $client->request('GET', $down);
    $html = (string)$res->getBody();
    $dw = QueryList::html($html)->find(".panel-body a")->map(function ($R) {
        return [
            'name' => $R->text(),
            'href' => $R->href
        ];
    })->all();
    return [
        'thumb' => $Row->find(".focus img")->attr('src'),
        'title' => $title,
        'href' => $href,
        'id' => $id,
        'date' => $date,
        'author' => $author,
        'text' => $text,
        'dw' => $dw
    ];
});
print_r($title->all());

說明

AE博客安裝有waf(防火牆)建議三個小時執行一次,可以使用Redis緩存。

相關說明:

1、VIP會員無限製任意下載,免積分。立即前往開通>>

2、下載積分可通過日常 簽到綁定郵箱 以及 積分兌換 等途徑獲得!

3、本站資源大多存儲在雲盤,如出現鏈接失效請評論反饋,如有密碼,均為:www.ipipn.com。

4、所有站內資源僅供學習交流使用。未經原版權作者許可,禁止用於任何商業環境,否則後果自負。為尊重作者版權,請購買正版作品。

5、站內資源來源於網絡公開發表文件或網友分享,如侵犯您的權益,請聯係管理員處理。

6、本站提供的源碼、模板、軟件工具等其他資源,都不包含技術服務,請大家諒解!

7、源碼、模板等資源會隨著技術、壞境的升級而存在部分問題,還請慎重選擇。

PS.源碼均收集自網絡,如有侵犯閣下權益,請發信件至: admin@ipipn.com .


源站網 » 實戰使用QueryListPHP框架采集AE博客文章

發表評論

讚助本站發展 維持服務器消耗

全站源碼免費下載 立刻讚助