微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Goutte PHP 爬虫库

程序名称:Goutte

授权协议: MIT

操作系统: 跨平台

开发语言: PHP

Goutte 介绍

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

示例代码

require_once '/path/to/goutte.phar';

use Goutte\Client;

//发送请求
$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: %s\n", $nodes->text()));
}

printf("Nb tasks: %d\n", $crawler->filter('#nb_tasks')->text());

Goutte 官网

https://github.com/fabpot/Goutte

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐