例如想在当前目录下保存目标文档
那么在写with open操作的时候,按照如下方式写就可以了:
file_path = r"C:\Users\lenovo\Desktop\python\arithmetic\{}吧第{}页HTML内容.txt".format(self.tieba_name, page_number)
with open(file_path, "w", encoding="utf-8") as f:
f.write(html_str)
文件就会自动生成
效果如下: