Home  >  Article  >  Database  >  Nutch2.1+mysql+solr3.6.1+中文网站抓取

Nutch2.1+mysql+solr3.6.1+中文网站抓取

WBOY
WBOYOriginal
2016-06-07 15:52:431067browse

1、mysql 数据库配置 linux mysql安装步骤省略。 创建数据库与表 [sql] view plaincopyprint? CREATE DATABASE nutch DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; CREATE TABLE `webpage`( `id` varchar (767) CHARACTER SET latin1 NOT N

1、mysql 数据库配置

    linux mysql安装步骤省略。

    创建数据库与表 <br>

   

[sql] view plaincopyprint?

  1. CREATE DATABASE nutch DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;  
  2.   
  3.    CREATE TABLE `webpage` (  
  4.   
  5.        `id` varchar(767) CHARACTER SET latin1 NOT NULL,  
  6.   
  7.        `headers` blob,  
  8.   
  9.        `text` mediumtext DEFAULT NULL,  
  10.   
  11.        `status` int(11) DEFAULT NULL,  
  12.   
  13.        `markers` blob,  
  14.   
  15.        `parseStatus` blob,  
  16.   
  17.        `modifiedTime` bigint(20) DEFAULT NULL,  
  18.   
  19.        `score` float DEFAULT NULL,  
  20.   
  21.        `typ` varchar(32) CHARACTER SET latin1 DEFAULT NULL,  
  22.   
  23.        `baseUrl` varchar(512) CHARACTER SET latin1 DEFAULT NULL,  
  24.   
  25.        `content` mediumblob,  
  26.   
  27.        `title` varchar(2048) DEFAULT NULL,  
  28.   
  29.        `reprUrl` varchar(512) CHARACTER SET latin1 DEFAULT NULL,  
  30.   
  31.        `fetchInterval` int(11) DEFAULT NULL,  
  32.   
  33.        `prevFetchTime` bigint(20) DEFAULT NULL,  
  34.   
  35.        `inlinks` mediumblob,  
  36.   
  37.        `prevSignature` blob,  
  38.   
  39.        `outlinks` mediumblob,  
  40.   
  41.        `fetchTime` bigint(20) DEFAULT NULL,  
  42.   
  43.        `retriesSinceFetch` int(11) DEFAULT NULL,  
  44.   
  45.        `protocolStatus` blob,  
  46.   
  47.        `signature` blob,  
  48.   
  49.        `metadata` blob,  
  50.   
  51.        PRIMARY KEY (`id`)  
  52.   
  53.    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;   
<br> <br> 2、安装nutch2.1<br> A、 nutch下载地址:http://apache.etoak.com/nutch/2.1/apache-nutch-2.1-src.zip

    下载完成后家压缩, <br>

B、以下将nutch的根目录定位${APACHE_NUTCH_HOME}.

C、配置nutch对mysql的支持,修改${APACHE_NUTCH_HOME}/ivy/ivy.xml文件

    将这行的注释取消default”/>

    修改${APACHE_NUTCH_HOME}/conf/gora.properties文件,

        注释默认存储配置 <br> <br>

[html] view plaincopyprint?

  1. ###############################  
  2.   
  3.    # Default SqlStore properties #  
  4.    ###############################  
  5.    #gora.sqlstore.jdbc.driver=org.hsqldb.jdbc.JDBCDriver  
  6.    #gora.sqlstore.jdbc.url=jdbc:hsqldb:hsql://localhost/nutchtest  
  7.    #gora.sqlstore.jdbc.user=sa  
  8.    #gora.sqlstore.jdbc.password=  
  9.   
  10.        取消以下代码注释,  
  11.   
  12.    ###############################  
  13.    # MySQL properties             
  14.     ################################  
  15.   
  16.    gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver  
  17.   
  18.    gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true  
  19.   
  20.    gora.sqlstore.jdbc.user=xxxxx(mysql用户名)  
  21.   
  22.    gora.sqlstore.jdbc.password=xxxxx(mysql密码)  
<br> <br>

<br>

       D、修改${APACHE_NUTCH_HOME}/conf/nutch-site.xml 加入如下代码:

[html] view plaincopyprint?

  1. property>  
  2.   
  3. name>http.agent.namename>  
  4.   
  5. value>Your Nutch Spidervalue>  
  6.   
  7. property>  
  8.   
  9. property>  
  10.   
  11. name>http.accept.languagename>  
  12.   
  13. value>ja-jp, en-us,en-gb,en;q=0.7,*;q=0.3value>  
  14.   
  15. description>Value of the “Accept-Language” request header field.  
  16.   
  17. This allows selecting non-English language as default one to retrieve.  
  18.   
  19. It is a useful setting for search engines build for certain national group.  
  20.   
  21. description>  
  22.   
  23. property>  
  24.   
  25. property>  
  26.   
  27. name>parser.character.encoding.defaultname>  
  28.   
  29. value>utf-8value>  
  30.   
  31. description>The character encoding to fall back to when no other information  
  32.   
  33. is availabledescription>  
  34.   
  35. property>  
  36.   
  37. property>  
  38.   
  39. name>storage.data.store.classname>  
  40.   
  41. value>org.apache.gora.sql.store.SqlStorevalue>  
  42.   
  43. description>The Gora DataStore class for storing and retrieving data.  
  44.   
  45. Currently the following stores are available: ….  
  46.   
  47. description>  
  48.   
  49. property>  
<br> <br>
E、使用ant编译  ${APACHE_NUTCH_HOME} 。

<br>

F、设置待抓取的网站

    cd ${APACHE_NUTCH_HOME}/runtime/local <br>     mkdir -p urls <br>     echo 'http://nutch.apache.org/' > urls/seed.txt

G、执行爬行操作: bin/nutch crawl urls -depth 3 -topN 5

    执行完在mysql中即可以查看到爬虫抓取的内容

<br>

3、安装solr,对nutch抓取的内容进行索引

    (注意:参考资料中推荐使用solr4.0版本,4.0的两个版本我都试了,没有成功,所以替换为3.6.1版本) <br>

     solr下载地址:http://www.fayea.com/apache-mirror/lucene/solr/3.6.1/apache-solr-3.6.1.zip

<br>

    A、解压缩下载包,

    B、下载  http://nlp.solutions.asia/wp-content/uploads/2012/08/schema.xml替换${APACHE_SOLR_HOME}/example/solr/conf/schema.xml.

    C、启动solr 

        cd ${APACHE_SOLR_HOME}/example

    java -jar start.jar

    <strong>D</strong>、在浏览器输入地址http://localhost:8983/solr  测试是否启动成功。

        E、另起linux终端,输入如下命令,使solr对nutch抓取内容进行索引。<br>

            cd ${APACHE_NUTCH_HOME}/runtime/local/

      bin/nutch solrindex http://127.0.0.1:8983/solr/ -reindex

4、测试

    在浏览器输入   http://localhost:8983/solr  ,看到如下界面:

<br> Nutch2.1+mysql+solr3.6.1+中文网站抓取<br>

在文本框中输入 content:nutch 点击查询,便可查处内容中包含nutch关键字的网页 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn