如何从 XPath 查询中的先前属性值中提取嵌入的属性值?
我试图从 html 的以下部分中的 onclick 属性中“选择”链接
<span onclick="Javascript:document.quickFindForm.action='/blah_blah'"
class="specialLinkType"><img src="blah"></span>
,但无法获得比以下 XPath 更进一步的信息,
//span[@class="specialLinkType"]/@onclick
该 XPath 只返回
Javascript:document.quickFindForm.action
Any ideas on how to pick out that link inside of the QuickFindForm .action 带有 XPath?
I'm trying to "select" the link from the onclick attribute in the following portion of html
<span onclick="Javascript:document.quickFindForm.action='/blah_blah'"
class="specialLinkType"><img src="blah"></span>
but can't get any further than the following XPath
//span[@class="specialLinkType"]/@onclick
which only returns
Javascript:document.quickFindForm.action
Any ideas on how to pick out that link inside of the quickFindForm.action
with an XPath?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 Java 应用程序中尝试了 XPath,它工作正常:
结果:
I tried the XPath in a Java application and it worked ok:
Result:
如果 Scrapy 支持 XPath 字符串函数,这将起作用
它看起来也支持正则表达式。像这样的东西应该有效
警告:我无法测试第二个解决方案,您必须检查
\'
在这种情况下是单引号的正确转义序列。If Scrapy supports XPath string functions this will work
It looks like it also supports regex. Something like this should work
Caveat: I can't test the second solution and you will have to check that
\'
is the proper escape sequence for single quotes in this case.我用的是xquery,但是xpath中应该是一样的。我使用了一个 xpath 函数“tokenize”,它根据正则表达式分割字符串(http://www.xqueryfunctions.com/xq/fn_tokenize.html)。
在这种情况下,我根据“ ' ”分割字符串,
在 xpath 中应该是:
I used xquery but it should be the same in xpath. I used an xpath function "tokenize" that splits a string based on a regular expression (http://www.xqueryfunctions.com/xq/fn_tokenize.html).
In this case I split the string basing on " ' "
That in xpath shoud be: