2020-01-14 19:17:29 +08:00

53 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# phpspider -- PHP蜘蛛爬虫框架
《我用爬虫一天时间“偷了”知乎一百万用户只为证明PHP是世界上最好的语言 》所使用的程序
phpspider是一个爬虫开发框架。使用本框架你不用了解爬虫的底层技术实现爬虫被网站屏蔽、有些网站需要登录或验证码识别才能爬取等问题。简单几行PHP代码就可以创建自己的爬虫利用框架封装的多进程Worker类库代码更简洁执行效率更高速度更快。
demo目录下有一些特定网站的爬取规则只要你安装了PHP环境代码就可以在命令行下直接跑。 对爬虫感兴趣的开发者可以加QQ群一起讨论147824717。
下面以糗事百科为例, 来看一下我们的爬虫长什么样子:
```
$configs = array(
'name' => '糗事百科',
'domains' => array(
'qiushibaike.com',
'www.qiushibaike.com'
),
'scan_urls' => array(
'http://www.qiushibaike.com/'
),
'content_url_regexes' => array(
"http://www.qiushibaike.com/article/\d+"
),
'list_url_regexes' => array(
"http://www.qiushibaike.com/8hr/page/\d+\?s=\d+"
),
'fields' => array(
array(
// 抽取内容页的文章内容
'name' => "article_content",
'selector' => "//*[@id='single-next-link']",
'required' => true
),
array(
// 抽取内容页的文章作者
'name' => "article_author",
'selector' => "//div[contains(@class,'author')]//h2",
'required' => true
),
),
);
$spider = new phpspider($configs);
$spider->start();
```
爬虫的整体框架就是这样, 首先定义了一个$configs数组, 里面设置了待爬网站的一些信息, 然后通过调用```$spider = new phpspider($configs);```和```$spider->start();```来配置并启动爬虫.
#### 运行界面如下:
![](http://www.epooll.com/zhihu/pachong.gif)
更多详细内容,移步到:
[开发文档](http://doc.phpspider.org)