如何使用python中的scrapy从图像元素中提取imdb中电影的评分 [英] How to extract the rating of a movie in imdb from an image element using scrapy in python

查看:22
本文介绍了如何使用python中的scrapy从图像元素中提取imdb中电影的评分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pythons scrapy 来抓取 imdb.但是我无法从页面获取评级信息,如下所示:

I am trying to scrape imdb using pythons scrapy. however I am not being able to get the rating info from the page as shown below:

图片

我正在使用以下代码:

from scrapy.spiders import Spider
from scrapy.selector import Selector
from imdb.items import ImdbItem


class ImdbSpider(Spider):
    name = "imdb"
    allowed_domains = ["imdb.com"]
    start_urls = [
        "http://www.imdb.com/title/tt0068646/reviews?ref_=%20best",

    ]
def parse(self, response):
    sel = Selector(response)
    ratings = sel.xpath('//div[contains(@id,"tn15content")]/div/img')
    items = []

        for rating in ratings:
        item = ImdbItem()
        item['rating'] = rating.xpath('/@alt').extract()
        items.append(item)  

return items

如果这是一个非常基本的问题,我很抱歉,但我对 python 和网络抓取很陌生,无法真正弄清楚如何实现,所以有人可以指导我吗??

I am sorry if this is a very basic question but I am very new to python and web scraping and can't really figure out how to achieve so would someone kindly guide me??

推荐答案

/是多余的,使用:

rating.xpath('@alt').extract_first()

这篇关于如何使用python中的scrapy从图像元素中提取imdb中电影的评分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆