xpath查询图片网址(xpath query for image url)

编程入门 行业动态 更新时间:2024-10-19 03:32:45
xpath查询图片网址(xpath query for image url)

我正在为我的学校报纸写一个应用程序,它通过wordpress完全在线运行。 我正在使用Hpple解析html。 从以下内容:

</div> <div id="fs-2" class="fs"> <div id="fsh-2" class="fsh"> <div id="fdh-2" class="fdh"><a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/">Hit or &#8216;Mis&#8217;: Les Miserables Review<br> by *******</a></div> <a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/"><img src="http://www.mabearnews.com/wp-content/uploads/2012/12/les-miserables-2012-wallpapers-les-miserables-2012-movie-32697313-1280-800-600x375.jpg" id="fph-2" class="fph" /></a>

什么xpath查询字符串将返回图像url(img src)?

I am writing an app for my school newspaper, which is run completely online through wordpress. I am using Hpple to parse the html. From the following:

</div> <div id="fs-2" class="fs"> <div id="fsh-2" class="fsh"> <div id="fdh-2" class="fdh"><a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/">Hit or &#8216;Mis&#8217;: Les Miserables Review<br> by *******</a></div> <a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/"><img src="http://www.mabearnews.com/wp-content/uploads/2012/12/les-miserables-2012-wallpapers-les-miserables-2012-movie-32697313-1280-800-600x375.jpg" id="fph-2" class="fph" /></a>

What xpath query string would return the image url (img src)?

最满意答案

HTML内容格式不正确。

假设这是正确的html内容:

<div id="fs-2" class="fs"> <div id="fsh-2" class="fsh"> <div id="fdh-2" class="fdh"><a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/">Hit or &#8216;Mis&#8217;: Les Miserables Review<br> by *******</a></div> <a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/"><img src="http://www.mabearnews.com/wp-content/uploads/2012/12/les-miserables-2012-wallpapers-les-miserables-2012-movie-32697313-1280-800-600x375.jpg" id="fph-2" class="fph" /></a> </div> </div>

您可以使用此xpath查询获取图像URL:

//div[@id="fsh-2"]/a/img/@src

The html content is not well-formed.

Assuming this is the proper html content:

<div id="fs-2" class="fs"> <div id="fsh-2" class="fsh"> <div id="fdh-2" class="fdh"><a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/">Hit or &#8216;Mis&#8217;: Les Miserables Review<br> by *******</a></div> <a href="http://www.mabearnews.com/entertainment/2012/12/26/hit-or-mis-les-miserables-review/"><img src="http://www.mabearnews.com/wp-content/uploads/2012/12/les-miserables-2012-wallpapers-les-miserables-2012-movie-32697313-1280-800-600x375.jpg" id="fph-2" class="fph" /></a> </div> </div>

You can get the image URL with this xpath query:

//div[@id="fsh-2"]/a/img/@src

更多推荐

本文发布于:2023-07-26 15:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   图片   xpath   url   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!