Goutte怎麼取得a標籤裡面的url?或好用的PHP爬蟲庫,謝謝
<code><?php require('./Vendor/autoload.php'); use Goutte\Client; /** * */ class Spider { private $_client; private $_crawler; public $_news = [ 'title' => [], 'link' => [], 'content' => [], 'source' => [], 'date' => [], ]; public function __construct() { try { $this->_client = new Client(); $this->_crawler = $this->_client->request('GET', 'http://www.ningshan.gov.cn/Category_90/Index.aspx'); // $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 10); } catch (Exception $e) { throw new \Exception($e->getMessage(), 1); } } public function getDate() { $this->_crawler->filter('div#list>ul>li>span')->each(function ($node) { $this->_news['date'][] = $node->text(); }); } public function getTitle() { $link = $this->_crawler->selectLink('宁陕县召开政协八届二十二次次常委会')->link(); var_dump($link->getUri);die; $this->_crawler->filter('div#list>ul>li>a')->each(function ($node) { if ($node->text() !== '宁陕要闻') { $this->_news['title'][] = $node->text(); $this->_news['link'][] = $node->link(); $this->_news['source'][] = '宁陕要闻'; } }); } } //----------------------------------- try { $spider = new Spider(); $spider->getDate(); $spider->getTitle(); echo json_encode($spider->_news, JSON_UNESCAPED_UNICODE); } catch (Exception $e) { echo $e->getMessage(); } </code>
回覆內容:
Goutte怎麼取得a標籤裡面的url?或好用的PHP爬蟲庫,謝謝
<code><?php require('./Vendor/autoload.php'); use Goutte\Client; /** * */ class Spider { private $_client; private $_crawler; public $_news = [ 'title' => [], 'link' => [], 'content' => [], 'source' => [], 'date' => [], ]; public function __construct() { try { $this->_client = new Client(); $this->_crawler = $this->_client->request('GET', 'http://www.ningshan.gov.cn/Category_90/Index.aspx'); // $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 10); } catch (Exception $e) { throw new \Exception($e->getMessage(), 1); } } public function getDate() { $this->_crawler->filter('div#list>ul>li>span')->each(function ($node) { $this->_news['date'][] = $node->text(); }); } public function getTitle() { $link = $this->_crawler->selectLink('宁陕县召开政协八届二十二次次常委会')->link(); var_dump($link->getUri);die; $this->_crawler->filter('div#list>ul>li>a')->each(function ($node) { if ($node->text() !== '宁陕要闻') { $this->_news['title'][] = $node->text(); $this->_news['link'][] = $node->link(); $this->_news['source'][] = '宁陕要闻'; } }); } } //----------------------------------- try { $spider = new Spider(); $spider->getDate(); $spider->getTitle(); echo json_encode($spider->_news, JSON_UNESCAPED_UNICODE); } catch (Exception $e) { echo $e->getMessage(); } </code>
現找的
<code>$crawler = $client->request('GET', 'http://www.symfony.com/blog/'); $link = $crawler->selectLink('Security Advisories')->link(); print_r($link->getUri());</code>
手冊:http://symfony.com/doc/curren...
GIT:https://github.com/FriendsOfP...
採集類參考:http://flc.ren/2016/06/528.html

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3漢化版
中文版,非常好用

Dreamweaver Mac版
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。