nutch采集部署
程序员文章站
2022-06-16 08:03:16
...
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。
推荐阅读
-
Yolov5部署成为Python接口(用flask实现,yolo5写成接口)
-
分析nginx日志并屏蔽采集者ip(nginx屏蔽ip配置实例)
-
将Eclipse中的Web项目部署到Eclipse的方法[图文]
-
浅谈Scrapy网络爬虫框架的工作原理和数据采集
-
PHP+fiddler抓包采集微信文章阅读数点赞数的思路详解
-
Centos7.5安装mysql5.7.24二进制包方式部署
-
ASP.NET Core部署前期准备 使用Hyper-V安装Ubuntu Server 16.10
-
网站被采集怎么办 一招制服!
-
eclipse怎么部署tomcat服务器(讲解eclipse配置tomcat环境)
-
eclipse怎么部署tomcat服务器(讲解eclipse配置tomcat环境)