One - One Code All

Blog Content

lxml跳过子节点直接提取文本string()

Python   2014-03-20 21:59:19

一次性提取指定多标签里的所有文字。string()

bloger = selector.xpath("//a[@class='author-name blue-link']")
print(bloger[0].xpath('string(.)').strip())


>>> from lxml import etree
>>> result = html.xpath("//td")
>>> tds[3].xpath('string(.)').strip().replace("%","")


    
        
    11.30%
        
        
    



    
        
    1.28%
        
        
    

在xpath语法里面,点(.)表示当前节点.


上一篇:lxml库element转换为字符串
下一篇:airflow的参数

The minute you think of giving up, think of the reason why you held on so long.