我需要一些幫助來從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