简体   繁体   中英

Not able to extract data in forloop using scrapy

I am new to Scrapy and Python. I am trying to extract data from website(" https://in.bookmyshow.com/bengaluru/movies ") using forloop but it dosen't seem to be working

def parse(self, response):
      for sel in response.xpath('//div[@class="mv-row"]'):
          item = ExampleItem()
          item['Moviename'] = sel.xpath('.//a[@class="__movie-name"]//text()').extract()
          item['Language'] = sel.xpath('.//li[@class="__language"]//text()').extract()
          item['Info'] = sel.xpath('.//div[@class="__rounded-box __genre"]/text()').extract()
          yield item

The locators themselves are correct, you just need to fix the container locator you are looping over:

Replace:

for sel in response.xpath('//div[@class="mv-row"]'):

with:

for sel in response.xpath('//div[contains(@class, "movie-card")]'):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM