已删除的元素未显示在.jl文件中

时间:2018-05-09 17:03:59

标签: python python-3.x scrapy

快速背景我正在学习使用Python编写代码并同时学习刮擦。我的问题是,当我运行此代码时,控制台显示确实想要的内容被删除,但是当我打开.jl文档时它是空的。由于我是初学者,可能会有很多我错过的东西。如果我错过了类似的帖子,请提前感谢您的帮助和对不起。

import scrapy

class ProgxSpider(scrapy.Spider):
    name = 'progx'
    allowed_domains = ['random.com']
    start_urls = ['https://www.random.com.html']


    def parse(self, response):
         locations = []

        for i in response.selector.xpath('//div[@class="property-info- 
location ellipsis-element-control"]/text()').extract():
            locations.append(i)
        print(locations)

1 个答案:

答案 0 :(得分:0)

您需要使用yield而不是仅打印locations才能使输出存在于.jl文件中

yield {'locations':locations}
相关问题