如何使用 XPath 通过链接文本找到链接 URL? [英] How can I find the link URL by link text with XPath?

查看:62
本文介绍了如何使用 XPath 通过链接文本找到链接 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个格式良好的 XHTML 页面.当我有链接的文本时,我想找到链接的目标 URL.

示例

<a href="http://stackoverflow.com">编程问题网站</a><a href="http://cnn.com">新闻</a>

我想要一个 XPath 表达式,这样如果给定 programming questions site 它会给 http://stackoverflow.com,如果我给它 news 它会给 http://cnn.com.

解决方案

应该类似于:

<前>//a[text()='text_i_want_to_find']/@href

I have a well formed XHTML page. I want to find the destination URL of a link when I have the text that is linked.

Example

<a href="http://stackoverflow.com">programming questions site</a>
<a href="http://cnn.com">news</a>

I want an XPath expression such that if given programming questions site it will give http://stackoverflow.com and if I give it news it will give http://cnn.com.

解决方案

Should be something similar to:

//a[text()='text_i_want_to_find']/@href

这篇关于如何使用 XPath 通过链接文本找到链接 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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