我有以下html:
<h2>blah</h2>
html content to extract
(here can come tags, nested structures too, but no top-level h2)
<h2>other blah</h2>
是否可以在不使用python中使用
string.split("<h2>")
的情况下提取内容?(例如,使用BeautifulSoup或其他一些库?)
最佳答案
以下是使用http://htql.net中的HTQL的一些测试代码:
sample="""<h2>blah</h2>
html content to extract
<div>test</div>
<h2>other blah<h2>
"""
import htql
htql.query(sample, "<h2 sep excl>2")
# [('\n html content to extract \n <div>test</div>\n ',)]
htql.query(sample, "<h2 sep> {a=<h2>:tx; b=<h2 sep excl>2 | a='blah'} ")
# [('blah', '\n html content to extract \n <div>test</div>\n ')]
关于python - 如何在python中的两个不同标签之间提取html?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19934496/