首页 > 解决方案 > 如何使用stormcrawler从网站抓取特定数据

问题描述

我正在使用stormcrawler(v 1.16)抓取新闻网站并将数据存储在Elasticsearch(v 7.5.0)上。我的 crawler-conf 文件是Stormcrawler 文件。我使用 kibana 进行可视化。我的问题是

编辑:我正在考虑在内容索引中添加一个字段。所以我在 src/main/resources/parsefilter.json 、ES_IndecInit.sh 和 Crawler-conf.yaml 中进行了更改。我添加的 XPATH 是正确的。我已添加为

"parse.pubDate":"//META[@itemprop=\"datePublished\"]/@content"

在解析过滤器中。

parse.pubDate =PublishDate

在 crawler-conf 中并添加

PublishDate": { "type": "text", "index": false, "store": true}

在 ES_IndexInit.sh 的属性中。但我仍然没有在 kibana 或 elasticsearch 中获得任何名为 PublishDate 的字段。ES_IndexInit.sh 映射如下:

{
  "mapping": {
    "_source": {
      "enabled": false
    },
    "properties": {
      "PublishDate": {
        "type": "text",
        "index": false,
        "store": true
      },
      "content": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "description": {
        "type": "text",
        "store": true
      },
      "domain": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "host": {
        "type": "keyword",
        "store": true
      },
      "keywords": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "title": {
        "type": "text",
        "store": true
      },
      "url": {
        "type": "keyword",
        "store": true
      }
    }
  }
}

标签: web-crawlerapache-stormdata-extractionstormcrawler

解决方案


仅索引站点中的新闻页面的一种方法是依赖站点地图,但并非所有站点都会提供这些。

或者,您需要一种机制作为解析的一部分,可能在 ParseFilter 中,以确定页面是新闻项目,并根据索引期间元数据中存在的键/值进行过滤。

在CommonCrawl的新闻抓取数据集中完成的方式是种子 URL 是站点地图或 RSS 提要。

要不索引内容只需注释掉

  indexer.text.fieldname: "content"

在配置中。


推荐阅读