Maison  >  Questions et réponses  >  le corps du texte

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 Il y a quelques jours1001

répondre à tous(0)je répondrai

Pas de réponse
  • Annulerrépondre