我正在为我的学校报纸编写一个应用程序,该应用程序通过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查询字符串会返回图片网址(img src)?
答案 0 :(得分:0)
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查询获取图片网址:
//div[@id="fsh-2"]/a/img/@src