【发布时间】:2017-03-21 17:58:52
【问题描述】:
我需要一些帮助来使用 xpath 从 html 页面中提取部分信息!我想提取评论的评分
示例:这是HTML 代码
<div id="BVRRRatingOverall_Rating_Summary_1" class="BVRRRating BVRRRatingNormal BVRRRatingOverall">
<div class="BVRRLabel BVRRRatingNormalLabel">Overall rating </div>
<div class="BVRRRatingNormalImage"><img src="/4_9/5/rating.gif" class="BVImgOrSprite" alt="4.9 out of 5" title="4.9 out of 5" width="85" height="16"></div>
<span itemprop="aggregateRating" itemscope="" itemtype="http://schema.org/AggregateRating" class="BVRRRatingNormalOutOf">
<span itemprop="ratingValue" class="BVRRNumber BVRRRatingNumber">4.9</span>
<span class="BVRRSeparatorText">out of </span>
<span itemprop="bestRating" class="BVRRNumber BVRRRatingRangeNumber">5</span>
<meta itemprop="reviewCount" content="23">
</span>
</div>
从这段代码中,我想显示“4.9 out of 5”或包含“4.9”、“out of”、“5”的 3 个变量
我用过这个但是没用:
response.xpath('//div[@class="BVRRRatingNormalImage"]/img/@alt').extract()
有什么帮助吗?
【问题讨论】:
-
对于这个 html 示例应该可以使用这个 xpath 表达式:
//img[@class="BVImgOrSprite"]/@alt。但是没有站点链接和您的代码示例,我不知道它是否适合您。