【发布时间】:2018-12-05 16:33:39
【问题描述】:
我有几个看起来像这样的 html 页面:
标题
简介
目录:
选项1。艺术
选项2。运动
选项 3。跳舞
选择说明
选项1。艺术
一个。水彩 描述 湾。油画 描述 C。丙烯画 说明
选项2。运动
一个。篮球 描述 湾。蟋蟀 描述 C。足球 说明
选项 3。舞蹈
一个。霹雳舞
所有这些内容都以不同的 html 格式保存在每个 html 页面中。我想在每个页面的运动选项下收集整个文本。 (因为每个 html 页面的结构不同,所以除了找出 xpath 之外,我还能实现这一点吗)。
请帮忙。谢谢你。
示例 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> 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> 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> 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 section="sports".*?/>(.*)<div section="Dance" -
您好,我已经提供了示例 html。
标签: python html parsing web-scraping lxml