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