nutch采集部署

nutch的限制:
不能采集js动态加载页面内容和分页,对非动态js加载的分页,需要根据分页的情况,来进行设置爬取深度(分页与爬取深度存在关系)。这就限制了nutch全爬取存在很大的局限性,nutch本身要遵守robot协议,如果网址本身不允许被爬取,那么将不会被爬取。

nutch2.2.1部署

环境要求:
系统:Centos7.5
运行环境:java1.8
数据库:mysql5.7
编译环境:ant

下载nutch版本

http://archive.apache.org/dist/nutch/2.2.1/
在这里插入图片描述

编译nutch

修改${APACHE_NUTCH_HOME}/ivy/ivy.xml文件,将
<dependency org=”org.apache.gora” name=”gora-core” rev=”0.3″ conf=”*->default”/>
变成
<dependency org=”org.apache.gora” name=”gora-core” rev=”0.2.1″ conf=”*->default”/>
取消失gora-sql的注释
<dependency org=”org.apache.gora” name=”gora-sql” rev=”0.1.1-incubating” conf=”*->default” />
 取消mysql的注释
<dependency org=”mysql” name=”mysql-connector-java” rev=”5.1.18″ conf=”*->default”/>

创建数据库

#创建数据库(可以基于navicat等可视化管理工具)

CREATE DATABASE nutch DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;

#选择数据库

use nutch;

#创建表:

#注意此处的id长度,官方文档貌似也是767,但是我创建的时候出错了。默认编码格式是utf8mb4占四个字节,767/4 大致是190左右;

#如果是ut8则可设置到255,但是在使用ut8的时候,采集发生了错误。可能是字符集范围的关系吧。

CREATE TABLE `webpage` (
`id` varchar(190) NOT NULL,
`headers` blob,
`text` longtext DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`markers` blob,
`parseStatus` blob,
`modifiedTime` bigint(20) DEFAULT NULL,
`prevModifiedTime` bigint(20) DEFAULT NULL,
`score` float DEFAULT NULL,
`typ` varchar(32) CHARACTER SET latin1 DEFAULT NULL,
`batchId` varchar(32) CHARACTER SET latin1 DEFAULT NULL,
`baseUrl` varchar(767) DEFAULT NULL,
`content` longblob,
`title` varchar(2048) DEFAULT NULL,
`reprUrl` varchar(767) DEFAULT NULL,
`fetchInterval` int(11) DEFAULT NULL,
`prevFetchTime` bigint(20) DEFAULT NULL,
`inlinks` mediumblob,
`prevSignature` blob,
`outlinks` mediumblob,
`fetchTime` bigint(20) DEFAULT NULL,
`retriesSinceFetch` int(11) DEFAULT NULL,
`protocolStatus` blob,
`signature` blob,
`metadata` blob,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
ROW_FORMAT=COMPRESSED
DEFAULT CHARSET=utf8mb4;

修改${APACHE_NUTCH_HOME}/conf/gora.properties文件
注释掉原来Default SqlStore Properties采用的配置规则;
新增mysql配置项
###############################
# MySQL properties #
###############################
gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true
gora.sqlstore.jdbc.user=xxxxx
gora.sqlstore.jdbc.password=xxxxx

修改${APACHE_NUTCH_HOME}/conf/gora-sql-mapping.xml文件

将primarykey 的length属性修改为 190(原本为512) 和建立的数据库内长度对应

修改nutch-site.xml 添加必要配置
<property>
<name>http.agent.name</name>
<value>YourNutchSpider</value>
</property>
<property>
<name>http.accept.language</name>
<value>ja-jp, en-us,en-gb,zh-cn,en;q=0.7,*;q=0.3</value>
<description>Value of the “Accept-Language” request header field.
This allows selecting non-English language as default one to retrieve.
It is a useful setting for search engines build for certain national group.
</description>
</property>
<property>
<name>parser.character.encoding.default</name>
<value>utf-8</value>
<description>The character encoding to fall back to when no other information
is available</description>
</property>
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.sql.store.SqlStore</value>
<description>The Gora DataStore class for storing and retrieving data.
Currently the following stores are available: ….
</description>
</property>
<property>

<name>generate.batch.id</name>

<value>*</value>

</property>
<property>
<name>http.agent.name</name>
<value>spider</value>
<description>HTTP 'User-Agent' request header. MUST NOT be empty - 
  please set this to a single word uniquely related to your organization.

  NOTE: You should also check other related properties:

 http.robots.agents
 http.agent.description
 http.agent.url
 http.agent.email
 http.agent.version

  and set their values appropriately.

</description>
</property>

<property>
<name>http.robots.agents</name>
<value>spider,*</value>
<description>The agent strings we'll look for in robots.txt files,
  comma-separated, in decreasing order of precedence. You should
  put the value of http.agent.name as the first agent name, and keep the
  default * at the end of the list. E.g.: BlurflDev,Blurfl,*
</description>
</property>

存在的bug处理方式

进入nutch目录
ant

存在的bug处理方式

当爬取网上文档的时候:,不应该使用protocol-file,因为它是用于爬取本地文件的。如果你想爬取http、https,应当把plugin.includes 修改为httpclient。 

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值