如何在使用风暴爬行器爬行网页时排除具有id/class、页眉和页脚部分的HTM1的特定DIV



我正试图用带有页眉和页脚的html页面来抓取网站,这些页面对我的所有页面都很常见,还有两个单独的带有id的div。我想把id=firstSection,id=secondSection的div数据的内容存储在我的ES中。但整个带有页眉和页脚的html数据都存储在我中。有没有任何方法可以抓取特定的div id?或者我可以排除任何不存储到ES中的特定div内容吗?

注意:我试图在Exclude标记中添加div的class/id,但没有成功。

我正在使用Storm Crawler 1.17&ES-7.6

以下是我的配置和htmls

爬网程序配置文件

# text extraction for JSoupParserBolt
textextractor.include.pattern:
- DIV[id="maincontent"]
- DIV[itemprop="articleBody"]
- ARTICLE
- DIV[id="block-edu-bootstrap-subtheme-content" class="block block-system block-system-main-block"]
- MAIN[role="main"]
- DIV[id="content--news"]
- DIV[id="content--person"]
- ARTICLE[class="node container node--type-facility facility-full node-101895 node--promoted node--view-mode-full py-5"]
- ARTICLE[class="node container node--type-spotlight spotlight-full node-90543 node--promoted node--view-mode-full py-5"]
- DIV[class="field field--name-field-content field--type-entity-reference-revisions field--label-hidden field__items"]
- BODY

textextractor.exclude.tags:
- STYLE
- SCRIPT
- HEADER[class="fixed-header"]
- FOOTER[class="fixed-footer"]

和我使用的示例html文件

index.html


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Implement Sticky Header and Footer with CSS</title>
<style>
/* Add some padding on document's body to prevent the content
to go underneath the header and footer */
body {
padding-top: 60px;
padding-bottom: 40px;
}

.fixed-header, .fixed-footer {
width: 100%;
position: fixed;
background: #333;
padding: 10px 0;
color: #fff;
}

.fixed-header {
top: 0;
}

.fixed-footer {
bottom: 0;
}

.container {
width: 80%;
margin: 0 auto; /* Center the DIV horizontally */
}

.welcome-box {
background: #cccccc;
border: 1px solid #333333;
}

nav a {
color: #fff;
text-decoration: none;
padding: 7px 25px;
display: inline-block;
}
</style>
</head>
<body>
<div class="fixed-header">
<div class="container">
<nav>
<a href="#">Home</a> <a href="#">About</a> <a href="#">Products</a>
<a href="#">Services</a> <a href="#">Contact Us</a>
</nav>
</div>
</div>
<div id="firstSection">
<div class="container">
<div class="welcome-box">
<h1>Welcome</h1>
<p>Hi, welcome to our website.</p>
</div>
<div class="welcome-box">
<h1>Welcome</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
</div>
</div>
</div>
<div id="secondSection">
<div class="container">
<div class="welcome-box">
<h1>Welcome2</h1>
<p>Hi, welcome to our second section.</p>
</div>
<div class="welcome-box">
<h1>Second section</h1>
<p>Hi, welcome to our second section.</p>
</div>
</div>
</div>
<div id="thirdSection">
<div class="container">
<div class="welcome-box">
<h1>Welcome</h1>
<p>Dont crawl this section.</p>
</div>
<div class="welcome-box">
<h1>Welcome</h1>
<p>Dont crawl this section</p>
</div>
</div>
</div>
<div class="fixed-footer">
<div class="container">Copyright &copy; 2020 Your Company</div>
</div>
</body>
</html>

不确定排除为什么不起作用(也没有时间在您提供的示例上进行测试(,但您可以配置XPathFilter以提取元数据中特定键下您感兴趣的元素,然后配置索引器将该键的内容存储为ES中的字段。

有关如何设置XPathFilter的示例,请参阅原型中的解析过滤器配置。

最新更新