<html>my news article</html>
<title>scraping</title>
<p>the world of so many articles</p>
<p>has been placed in this blocknotes</p>
<p>and i really wanna scraped that html structure just as it is</p>
<p>with all the tags in the scrapped data</p>
如何废弃所有标签?
我希望抓取的数据像............
答案 0 :(得分:1)
此Python脚本可能有所帮助:
from lxml import html
HTML = """<html>
<title>scraping</title>
<p>the world of so many articles</p>
<p>has been placed in this blocknotes</p>
<p>and i really wanna scraped that html structure just as it is</p>
<p>with all the tags in the scrapped data</p>
</html>"""
tree = html.fromstring(HTML)
print ' '.join("<p>{}</p>".format(x) for x in tree.xpath('//p/text()'))
<强>输出:强>
<p>the world of so many articles</p> <p>has been placed in this blocknotes</p> <p>and i really wanna scraped that html structure just as it is</p> <p>with all the tags in the scrapped data</p>