【发布时间】:2016-01-27 17:45:18
【问题描述】:
我正在寻求使用 BeautifulSoup 来解析一种网页上的文本,代码如下:
import urllib
import re
html = urllib.urlopen('http://english.hani.co.kr/arti/english_edition/e_national/714507.html').read()
content= str(soup.find("div", class_="article-contents"))
所以我的目标是至少解析出第一段中的第一句话或前几句话。
因为段落没有被<p> 标签包围,所以到目前为止我最好的策略是在content 中找到</h4> 和<p> 之间的文本(发生这种情况成为第一段)
目标文本如下所示:
<div class="article-contents">
<div class="article-alignC">
<table class="photo-view-area">
<tr>
<td>
<img alt="" border="0" src="http://img.hani.co.kr/imgdb/resize/2015/1024/00542577201_20151024.JPG" style="width:590px;"/>
</td>
</tr>
</table>
</div>
<h4></h4>
(这是我要解析的内容,在<h4> 和<p> 之间)
<p align="justify"></p>
我正在尝试直接在 BeautifulSoup 上执行此操作或使用正则表达式,但到目前为止仍然不成功。
【问题讨论】:
标签: python regex web-scraping beautifulsoup