将绝对基本 URL 附加到 xPath 相对 src 属性
是否有使用 xPath 将基本 url 附加到相对 src URL 的方法? 我想要从相对的图像 URL 获得绝对图像 URL。
例如:
要获取 src:
我使用:
img/@src
现在我想做它绝对并附加 http://myothersite.com/:
http://myothersite.com/images/image .jpg
任何提示将不胜感激。
谢谢
更新: http://myothersite.com 的源 HTML 结构:
<div id="main">
<div class="header">
<h2>Some title</h2>
<div id="date">8th March 2008</div>
</div>
<div id="content">
<div id="main-content">
<div class="region">
<div id="block-system-main">
<div class="block-content">
<div id="node-123" class="clearfix">
<div class="content">
<div class="body">
<!-- Here I want to grab absolute path, as http://myothersite.com/images/image.jpg -->
<p><img src="/images/image.jpg"/></p>
<p>Some content ....</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
完整语法:
上下文:
//div[@id='main']
标题:
//div[@id='main']/div[1]/h2
创建:
//div[@id='date']
正文:
//div[@id='node-123']/div/div
有错误的图像 < strong>XPath 选择器出现错误:无效表达式:
//div[@id='node-123']/div/div/*/concat('http://myothersite.com',img/@src)
Is there such a thing as to append the base url to the relative src URL with xPath?
I want to have absolute image URL from the relative one.
E.g.:
To grab the src:<img src="/images/image.jpg" />
I used:
img/@src
Now I want to make it absolute with appending http://myothersite.com/:
http://myothersite.com/images/image.jpg
Any hint would be very much appreciated.
Thanks
UPDATE:
source HTML structure of http://myothersite.com:
<div id="main">
<div class="header">
<h2>Some title</h2>
<div id="date">8th March 2008</div>
</div>
<div id="content">
<div id="main-content">
<div class="region">
<div id="block-system-main">
<div class="block-content">
<div id="node-123" class="clearfix">
<div class="content">
<div class="body">
<!-- Here I want to grab absolute path, as http://myothersite.com/images/image.jpg -->
<p><img src="/images/image.jpg"/></p>
<p>Some content ....</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Complete syntax:
Context:
//div[@id='main']
title:
//div[@id='main']/div[1]/h2
created:
//div[@id='date']
body:
//div[@id='node-123']/div/div
image with error There was an error with the XPath selector: Invalid expression:
//div[@id='node-123']/div/div/*/concat('http://myothersite.com',img/@src)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在寻找 XPATH
concat('http://myothersite.com',img/@src)
函数?例如,我认为你不能像这样使用
concat
。尝试:这会获取第一个
p/image
主体子项。Are you looking for XPATH
concat('http://myothersite.com',img/@src)
function? For example,I think you cannot use
concat
like that. Try:This gets the first
p/image
body child.