python 爬虫

speed=etree.HTML(res).xpath("//tr [contains(@class ,'odd')]/td[7]/div[contains(@class,'bar')]/@title")

图片描述

这个xpath 匹配到0.182 秒 总是匹配不到,希望大神赐教

ip 和端口都匹配了,我觉得我写的没有问题,谢谢!

阅读 2.6k
3 个回答

我用你的xpath匹配到了-.-||
是没有匹配全吗? 有个的tr标签没有class="odd"

你的//tr [contains(@class ,'odd')]/td[7]/div[contains(@class,'bar')]/@title
匹配的是整个属性,会返回 title="0.182秒", 如果你只想得到属性值,可以用fn:string函数,

speed=etree.HTML(res).xpath("string(//tr [contains(@class ,'odd')]/td[7]/div[contains(@class,'bar')]/@title)")

将返回 0.182秒

我复制你的没有匹配搭配

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题