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 ‘Mis’: 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 ‘Mis’: 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 ‘Mis’: 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/@srcThe 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 ‘Mis’: 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更多推荐
发布评论