class 包含空格时获取空数组

Get empty array when class containing spaces

Python 2.7

我想获取每个新的背景图像url和标题,但是当我尝试获取图像时我使用xpath总是得到空数组url。

这是我的尝试:

scrapy shell http://www.wownews.tw/fashion/movie

然后

response.body

我可以在终端上看到 html 数据。但是当我输入

response.xpath('//div[@class="text ng-scope"]')

获取空数组,我认为它应该可以工作。

问题的发生是因为 class 包含空格吗?

如何解决?任何帮助将不胜感激。

我尝试命令仍然得到空数组

response.xpath('//div[contains(concat(" ", normalize-space(@class), " "), "text ng-scope")]')

这里应有尽有

import json
import scrapy


class ListingSpider(scrapy.Spider):
    name = 'listing'

    start_urls = ['http://api.wownews.tw/f/pages/site/558fd617913b0c11001d003d?category=5590a6a3f0a8bf110060914d&children=true&limit=48&page=1']

    def parse(self, response):
        items = json.loads(response.body)['results']

        for item in items:
            yield item

参考https://medium.com/@yashpokar/scrape-any-website-in-the-internet-without-using-splash-or-selenium-68a6c9733369