写入新文件时找不到文件

时间:2019-06-07 16:13:42

标签: python

当我将网站的html写入文件时,我在Scrapy spider中得到了此错误消息。

with open('{}.html'.format(name), 'wb') as html_file:
   FileNotFoundError: [Errno 2] No such file or directory:'CHARCOAL.html'

98%的网站html都正确编写了,但是有些人抛出了此错误(文件名不同)。为确保我打印出这些名称,它们都存在

这是我用来写入文件的代码

#code here
name = response.xpath('//*[@id="itemTitle"]//text()').extract()[1]
with open('{}.html'.format(name), 'wb') as html_file:
    html_file.write(response.body)

0 个答案:

没有答案