>  Q&A  >  본문

python中selenium使用xpath如何排除某类子节点

使用:
browser.find_element_by_xpath("//div[@class='cnt f-brk']")
匹配:
<div class="cnt f-brk">negative1989:为了发自拍又发了一首新歌<img src="http://s1.music.126.net/style...
想要得出:
negative1989:为了发自拍又发了一首新歌
但是却是:
negative1989:为了发自拍又发了一首新歌<img src="http://s1.music.126.net/style...
后来改进:
browser.find_element_by_xpath("//div[@class='cnt f-brk']/*[name(.)!='img']")
却又得到:
negative1989

还有就是本来想是使用re.sub去掉<img ...>,得到的内容使用print输出居然报错,未果。

现在不知如何才好啊


高洛峰高洛峰2919일 전1006

모든 응답(0)나는 대답할 것이다

답장 없음
  • 취소회신하다