首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何获取html页中两个字符串之间的数据

如何获取html页中两个字符串之间的数据
EN

Stack Overflow用户
提问于 2018-06-27 05:29:36
回答 1查看 78关注 0票数 1

我有几个html页面是这样的:

标题

引言

目录:

option1。艺术

option2。体育运动

option3。跳舞

选择说明

option1。艺术

a.水彩描述b.油画描述c.丙烯酸绘画描述

option2。体育运动

a.篮球描述b.板球描述c.足球描述

option3。跳舞

a.街舞

所有这些内容都以不同的html格式保存在每个html页面中。我想收集在每个页面的体育选项下的整个文本。(除了找出xpath之外,我还能不能做到这一点,因为每个html页面的结构都不同)。

请帮帮忙。谢谢。

示例html:

<Document>
<TYPE>
<SEQUENCE>
<FILENAME>
<DESCRIPTION>
<TEXT>
<HTML>
<HEAD>
</HEAD>

<P style="font-family:times;;margin-left:10.0pt;text-indent:-10.0pt;"><FONT SIZE=2><B>

<!-- COMMAND=STYLE_ADDED,"margin-left:10.0pt;text-indent:-10.0pt;" -->

option 1. Art history: </B></FONT></P>

<P style="font-family:times;"><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The nature of art has been described by philosopher Richard Wollheim as "one of the most elusive of the traditional problems of human culture".[19] Art has been defined as a vehicle for the expression or communication of emotions and ideas </FONT></P>

<P style="font-family:times;;margin-left:10.0pt;text-indent:-10.0pt;"><FONT SIZE=2><B>

<!-- COMMAND=STYLE_ADDED,"margin-left:10.0pt;text-indent:-10.0pt;" -->

option 2. Sports division : </B></FONT></P>

<P style="font-family:times;"><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hundreds of sports exist, from those between single contestants, through to those with hundreds of simultaneous participants, either in teams or competing as individuals. In certain sports such as racing, many contestants may compete, simultaneously or consecutively, with one winner; in others, the contest (a match) is between two sides, each attempting to exceed the other.</FONT></P>

<P style="font-family:times;;margin-left:10.0pt;text-indent:-10.0pt;"><FONT SIZE=2><B>

<!-- COMMAND=STYLE_ADDED,"margin-left:10.0pt;text-indent:-10.0pt;" -->

option 3. Dance group: </B></FONT></P>

<P style="font-family:times;"><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An important distinction is to be drawn between the contexts of theatrical and participatory dance,[4] although these two categories are not always completely separate; both may have special functions, </FONT></P>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-27 09:05:09

在这里,我将使用jQuery .text(),因为它看起来完全符合您的要求(只显示所有选定节点的文本内容)。

除此之外,选择正确的元素是一个简单的问题,所以我们确实需要知道要选择什么“部分”。可能是这样的:

$("P:contains('option 2')").nextUntil("p:contains('option 3')").text()

console.log($("P:contains('option 2')").nextUntil("p:contains('option 3')").text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="scott">
<P style="font-family:times;;margin-left:10.0pt;text-indent:-10.0pt;"><FONT SIZE=2><B>

<!-- COMMAND=STYLE_ADDED,"margin-left:10.0pt;text-indent:-10.0pt;" -->

option 1. Art history: </B></FONT></P>

<P style="font-family:times;"><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The nature of art has been described by philosopher Richard Wollheim as "one of the most elusive of the traditional problems of human culture".[19] Art has been defined as a vehicle for the expression or communication of emotions and ideas </FONT></P>



<P style="font-family:times;;margin-left:10.0pt;text-indent:-10.0pt;"><FONT SIZE=2><B>

<!-- COMMAND=STYLE_ADDED,"margin-left:10.0pt;text-indent:-10.0pt;" -->

option 2. Sports division : </B></FONT></P>

<P style="font-family:times;"><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hundreds of sports exist, from those between single contestants, through to those with hundreds of simultaneous participants, either in teams or competing as individuals. In certain sports such as racing, many contestants may compete, simultaneously or consecutively, with one winner; in others, the contest (a match) is between two sides, each attempting to exceed the other.</FONT></P>

<div>some other random stuff here.</div>

<P style="font-family:times;;margin-left:10.0pt;text-indent:-10.0pt;"><FONT SIZE=2><B>

<!-- COMMAND=STYLE_ADDED,"margin-left:10.0pt;text-indent:-10.0pt;" -->

option 3. Dance group: </B></FONT></P>

<P style="font-family:times;"><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An important distinction is to be drawn between the contexts of theatrical and participatory dance,[4] although these two categories are not always completely separate; both may have special functions, </FONT></P>

</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51051610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档