环境:linux centos
安装nutch略;
配置nutch :
在nutch根目录下新建urls文件夹,里面新建一个url的txt文件 写入需要爬取的网站:例如,http://icbc.com.cn/
配置nutch-default.xml文件,或者将nutch-default文件需要配置的property拷贝到nutch-site文件中进行配置
<property>
<name>http.agent.name</name>
<value>nutchspider</value>
</property>
另外其他的属性需要根据网站的具体情况进行修改,例如
<property>
<name>file.content.limit</name>
<value>65536</value>
<description>The length limit for downloaded content using the file
protocol, in bytes. If this value is nonnegative (>=0), content longer
than it will be truncated; otherwise, no truncation at all. Do not
confuse this setting with the http.content.limit setting.
</description>
</property>
<name>file.content.limit</name>
<value>65536</value>
<description>The length limit for downloaded content using the file
protocol, in bytes. If this value is nonnegative (>=0), content longer
than it will be truncated; otherwise, no truncation at all. Do not
confuse this setting with the http.content.limit setting.
</description>
</property>
的value需要修改的大一点,否则会提示skip网页的情况。
配置regex-urlfilter.xml 在#accept anything else 后面添加+^http://www.icbc.com.cn/
配置gora.properties 在里面添加
gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
gora.sqlstore.jdbc.url=具体数据库url
gora.sqlstore.jdbc.user=用户名
gora.sqlstore.jdbc.password=密码
查看gora-sql-mapping.xml 文件,一般不需要做修改
在数据库中新建webpage的表,(若不建表,运行时会自动建表),
参考gora-sql-mapping.xml 文件字段信息进行建表,对于字段长度需要根据每个网站的情况进行调整,例如title,content等需要进行调整的长一些,
建议longtext类型
将jdbc驱动拷入到lib中,主要版本若版本不对可能会报错,使用5.1.6不会报错。
此时便可以运行nutch。
如有错误,需要根据网站的进行调整数据库的字段属性。