如何修复OSError:[Errno 22]无效参数:'\\?'

2024-09-28 20:59:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的windows10机器上安装了一个脏蜘蛛,它运行得很好!但我的问题是,当它完成最后一个项目时:

device.py, line 142, in parse_details
    with open(os.path.join('out', ro_product_model_created+".json"), "w") as f:
OSError: [Errno 22] Invalid argument: 'out\\?? (1.6.0-Nokia ????-Lumia925-TL1263-TL1263-S001-DESAY_TL1263_15012_140611-4.3-18).json'

我使用的是python3.6

^{pr2}$

我希望输出不会有任何错误。 它实际上是从json的每一行抓取单独的文件到out文件夹中。在

在命令上运行:

scrapy crawl androiddevice -a sr_term=nokia

谢谢, 宫殿


Tags: 项目inpy机器jsonparsedevicewith
1条回答
网友
1楼 · 发布于 2024-09-28 20:59:00

您没有在此处清理文件名:

with open(os.path.join('out', ro_product_model_created+".json"), "w") as f:
#                             ^^^^^^^^^^^^^^^^^^^^^^^^
    f.write(formatted_json)

您的案例中的ro_product_model_created包含{}等,这些不是有效的文件名字符

有关清理文件名的信息,请参阅相关问题:Turn a string into a valid filename?

我的个人喜好是:

^{pr2}$

相关问题 更多 >