我需要一些帮助来从xpath中用xpath提取部分信息!我想提取审查的评级 为例:这是HTML
代码如何在python scrapy中用Xpath提取信息
<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总分5”或3个变量包含“4.9”,“出”,“5”
我用这一点,但没有奏效:
response.xpath('//div[@class="BVRRRatingNormalImage"]/img/@alt').extract()
任何帮助吗?
股利不具备类“BVRRRatingNormalImage”。 – betseyb
抱歉betseyb!我只是把下面的HTML代码! –
对于这个html例子应该这个xpath表达式: '// img [@ class =“BVImgOrSprite”]/@ alt'。 但没有网站链接和你的代码的一些例子,我不知道它是否会为你工作。 – vold