鍍金池/ 問答/Python  Linux/ python里面的xpath string 方法報錯

python里面的xpath string 方法報錯

tr_list = self.driver.find_elements_by_xpath('//table[@class="hyreport-table tl"]/tbody//tr')
     for i in range(0,100):

           for i  in range(0,len(tr_list)):
                content=etree(tr_list[i]).xpath("string(//*[@class='pl20'])")
                source=etree(tr_list[i]).xpath('//td[@class="ellipsis"]/span/text()')
                size=etree(tr_list[i]).xpath('//td[5]/text()')
                report_time=etree(tr_list[i]).xpath('//td[6]/text()')
                print("獲取內(nèi)容為:下面打印的內(nèi)容")



Traceback (most recent call last):
      File "qimingpian.py", line 115, in <module>
        qimingpian().get_content()
      File "qimingpian.py", line 92, in get_content
        content=etree(tr_list[i]).xpath("string(//*[@class='pl20'])")
    TypeError: 'module' object is not callable
回答
編輯回答
舊顏

etree 我都是這么用的, 給你參考下

from lxml import etree   # 導(dǎo)入
selector = etree.HTML(str("HTML內(nèi)容")) 
result= selector.xpath('//div[@class="WB_handle"]//li[2]//em[2]/text()')
2017年10月11日 20:59
編輯回答
不討囍

看起來好像是用的selenium,這里取子節(jié)點的話我記得是直接tr_list[i].find_element_by_xpath() 就行了, 如果etree是從lxml導(dǎo)入的話我記得是不能這樣寫的。。

2017年8月22日 22:17