首页 > PHP资讯 > PHP培训技术 > PHP 爬虫库 Goutte

PHP 爬虫库 Goutte

PHP培训技术

Goutte 是一个抓取网站数据的 PHP 库。它提供了一个优雅的 API,这使得从远程页面上选择特定元素变得简单。

示例代码:

require_once '/path/to/goutte.phar';use GoutteClient;//发送请求$client = new Client();$crawler = $client->request('GET', 'http://www.oschina.net/');//点击链接$link = $crawler->selectLink('Plugins')->link();$crawler = $client->click($link);//提交表单$form = $crawler->selectButton('sign in')->form();$crawler = $client->submit($form, array('signin[username]' => 'fabien', 'signin[password]' => 'xxxxxx'));//提取数据$nodes = $crawler->filter('.error_list');if ($nodes->count()){  die(sprintf("Authentication error: %sn", $nodes->text()));}printf("Nb tasks: %dn", $crawler->filter('#nb_tasks')->text());
本文由欣才IT学院整理发布,未经许可,禁止转载。