<?php require_once "./phpQuery.php"; require_once "./QueryList.php"; //定义页码 $range=range(1,3); //循环获取数据 foreach ($range as $val){ $url=‘https://news.ke.com/bj/baike/0033/‘.‘pg‘.$val.‘/‘; $data=@QL\QueryList::Query($url,[ ‘img‘=>[‘.item>a>img‘,‘data-original‘,‘‘,function($item){ return $item; // $img= pathinfo($item,PATHINFO_EXTENSION ); //// print_r($img); // $img=‘hy_‘.rand(1,999).‘.‘.$img; //// return $img; // $lots=dirname(__DIR__).‘/public/uploads/img/‘.$img; // $lotsId=file_put_contents($lots,file_get_contents($item)); //// return $lots; // $accessKey="i823JQs3EZMXhqg3LBlOTwDD5iqVZXZmqLsCUqIs"; // $secretKey="uSVT59ZIn7hOHJV-UcLo4W-A5pQaREDirR_F7JnF"; // $uploadMgr = new \Qiniu\Storage\UploadManager(); // $auth = new \Qiniu\Auth($accessKey, $secretKey); // $token = $auth->uploadToken(‘jmin‘); // list($ret, $error) = $uploadMgr->putFile($token, $lotsId,$img); }], ‘title‘=>[‘.tit‘,‘html‘], ‘desn‘ => [‘.text>.summary‘,‘text‘], ‘rul‘ => [‘.text>a‘, ‘href‘], ])->data; foreach ($data as $v){ $pdo=new PDO(‘mysql:host=127.0.0.1;dbname=fy‘,‘root‘,‘root‘); $sql="insert into hy_articles (title,desn,img,rul,name,body)value (?,?,?,?,‘‘,‘‘)"; $ret=$pdo->prepare($sql); // 入库 $ret->execute([$v[‘title‘],$v[‘desn‘],$v[‘img‘],$v[‘rul‘]]); } }
<?php require_once "./phpQuery.php"; require_once "./QueryList.php"; $sql=new PDO(‘mysql:host=127.0.0.1;dbname=fy‘,‘root‘,‘root‘); $name="select id,rul from hy_articles where body=‘‘"; $ret=$sql->query($name); $kot= $ret->fetchAll(2); foreach ($kot as $val){ $id=$val[‘id‘]; $data=@\QL\QueryList::Query($val[‘rul‘],[ ‘body‘ => [‘.m-article‘,‘html‘], ‘name‘ => [‘.author‘,‘text‘] ])->data; // 获取发布者名字 $name=$data[0][‘name‘]; // 获取发布者文章 $body=$data[0][‘body‘]; // 修改语句 $updata="update hy_articles set body=?,name=? where id=?"; $bodys=$sql->prepare($updata); $bodys->execute([$body,$name,$id]); }