<?php
use QL\QueryList;
require_once './phpQuery.php';
require_once './QueryList.php';
$pdo = new PDO('mysql:host=127.0.0.1;dbname=zfw', 'root', 'root');
$page = range(1, 3);
foreach ($page as $value) {
$url = 'https://news.ke.com/sh/baike/0035/pg' . $value . "/";
$rules = [
'title' => ['.text .LOGCLICK', 'text'],
'desn' => ['.summary', 'text'],
'logo' => ['.lj-lazy', 'data-original', '', function ($item) {
$suffix = pathinfo($item, PATHINFO_EXTENSION);
$attr = md5($item) . time() . mt_rand(1, 9999999) . "." . $suffix;
$filepath = dirname(__DIR__) . "/public/admin/uploads/article/" . $attr;
file_put_contents($filepath, file_get_contents($item));
return "/admin/uploads/article/" . $attr;
}],
'url' => ['.text>.LOGCLICK', 'href']
];
$data[] = @ QueryList::Query($url, $rules)->data;
foreach ($data as $val){
foreach ($val as $k=>$v){
$sql = "insert into zfw_articles (title,desn,logo,url,author,main) values (?,?,?,?,'','')";
$stmt = $pdo->prepare($sql);
$stmt->execute([$v['title'],$v['desn'],$v['logo'],$v['url']]);
}
}
}
<?php
use QL\QueryList;
require_once './phpQuery.php';
require_once './QueryList.php';
$pdo = new PDO("mysql:host=127.0.0.1;dbname=zfw",'root','root');
$sql = "select id,url from zfw_articles where main=''";
$row = $pdo->query($sql)->fetchAll(2);
foreach ($row as $value){
$id = $value['id'];
$ret =@ QueryList::Query($value['url'],[
'author' => ['.author','text','',function($item){
return substr($item,'9','6');
}],
'main' => ['.bd','html']
])->data;
$author = $ret[0]['author'];
$main = $ret[0]['main'];
$upsql = "update zfw_articles set author=?,main=? where id=? ";
$stem = $pdo->prepare($upsql);
$stem->execute([$author,$main,$id]);
}