带有@href的Chrome元素检查器Xpath不会显示链接文本 [英] Chrome element inspector Xpath with @href won't show link text

查看:129
本文介绍了带有@href的Chrome元素检查器Xpath不会显示链接文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从网站的html中获取url,这里是我为StackOverflow的着陆页尝试的Xpath代码:

I am trying to get url from a website's html and here is the Xpath code I tried for StackOverflow's landing page:

$x('//*[@id="question-summary-30429261"]/div[2]/h3/a/@href')

我认为它应该在下列语句中的等号后面返回文本:

I think it should return the text after the equal sign in the following statement:

href=xxxx

但它没有。它只是返回null。我试着用谷歌搜索这个问题,但没有回答。有人知道为什么text @href不会显示链接文本吗?

but it doesn't. It just returns null. I tried Googling this question but no answer came up. Does someone know the reason why text @href won't show me the link text?

推荐答案

这应该有效:

$x('//*[@id="question-summary-30429261"]/div[2]/h3/a')[0].getAttribute('href')

这篇关于带有@href的Chrome元素检查器Xpath不会显示链接文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆