filename = title + '_' + first_published_time + '.txt'
在给文件命名时,原本想以标题加发布时间命名,结果错误提示OSError: [Errno 22] Invalid argument
原因:first_published_time的格式是2024-02-01-21:53:00,包含了特殊字符 :
OSError: [Errno 22] Invalid argument"通常表示给定的参数无效,可能是因为尝试创建文件夹时使用了无效的文件夹名。建议检查代码中创建文件夹的部分,并确保文件夹名符合文件系统的要求。在 Windows 系统中,文件夹名不能包含特殊字符(如 \ / : * ? " < > |),并且不能超过 255 个字符。
解决:替换时间格式中的冒号为其他可支持字符
first_published_time = first_published_time.replace(':', '`')