![]() |
1
imn1 2014-07-11 00:55:08 +08:00 ![]() a.xpath('//div/text()')[0] 试试
|
![]() |
2
ggarlic 2014-07-11 01:22:48 +08:00 ![]() 这坑我也踩过
text是空的原因是:text不是你以为的意思(一个标签的text内容)。text在文档中的定义是 Text before the first subelement. This is either a string or the value None, if there was no text. 除了楼上的方法,你也可以用itertext()方法来遍历 |
![]() |
3
binux 2014-07-11 02:18:11 +08:00 ![]() a.xpath('//div')[0].text_content()
|
![]() |
4
fy OP 多谢几位 搞定了
|
![]() |
5
pc10201 2014-07-11 09:38:06 +08:00
我为啥总觉得正则提取比xpath好呢?
|
![]() |
6
dingyaguang117 2014-07-11 10:31:56 +08:00
@pc10201 xpath 虽然会慢一点 不过写法简洁,而且准确性高
|