【发布时间】:2016-07-10 19:35:35
【问题描述】:
我有以下标签
<div class="example">
<p> text <a href="#"> link </a> text</p>
</div>
我想得到
<p> text <a href="#"> link </a> text</p>
所以 div 中的所有内容都带有类示例。 我正在使用
from lxml import html
page = requests.get('X')
tree = html.fromstring(page.content)
description = tree.xpath('//div[@class="example"]/p//text()')
这给了我一个段落标签列表,然后我将它们与
结合在一起description = ' '.join('<p>{0}</p>'.format(paragraph) for paragraph in description)
但是必须有一种方法可以直接获取 div 中的内容吗? 谢谢 卡尔
【问题讨论】:
标签: html web-scraping lxml