尝试写入,然后将数据从Scrapy读取到.txt文件中。这是我的爬虫程序的parse()
代码。你知道吗
def parse(self, response):
lastpage = response.xpath("/ol[@class='pagination']/li[7]/a/text()").extract()
with open('num_pages.txt', 'wb') as f:
f.write(lastpage)
此代码不会抛出错误,但稍后尝试读取相同的文件时会抛出错误。你知道吗
num_pages = int(open('num_pages.txt', 'r').strip())
即使有明显的数字_页面.txt在与spider相同的目录中,运行crawler会显示错误消息
No such file or directory: 'num_pages.txt.'
此外,即使写操作没有抛出错误,num_页面.txt手动打开时为空。文件I/o是否有问题?谢谢!你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐