s= requests.get(url)
d = html.fromstring(s.text)
q = d.xpath('//td[@class="postcell"]/div/div[@class="post-text"]/*')
for i in q:
print i
结果:
<Element p at 0x10ae26f70>
<Element p at 0x10ae26fc8>
<Element pre at 0x10ae32050>
<Element p at 0x10ae320a8>
<Element p at 0x10ae32100>
<Element p at 0x10ae32158>
<Element p at 0x10ae321b0>
<Element p at 0x10ae32208>
请问如何让段落信息显示出来?
1
JasperYanky 2015-06-15 16:50:08 +08:00
/text()
|
2
wico77 OP @JasperYanky 用text()的话就得到里面的文字,我想把成段的内容都得到。包括<p>, </p>
|
3
blueset 2015-06-15 17:14:55 +08:00 via Android
etree.tostring(i)
|