将python结果保存到文件
我有一些python代码返回url的结果,我不知道如何将其输出到txt或csv文件。任何帮助都将不胜感激将python结果保存到文件,python,csv,file,Python,Csv,File,我有一些python代码返回url的结果,我不知道如何将其输出到txt或csv文件。任何帮助都将不胜感激 import requests url = "https://website.com/completed?startDate=2021-01-01&endDate=2021-01-02" payload={} headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Author
import requests
url = "https://website.com/completed?startDate=2021-01-01&endDate=2021-01-02"
payload={}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxx',
'Cookie': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
试着这样做:
with open("my_file.txt", "w") as file:
file.write(response.text)
查看以了解有关用Python编写文件的更多信息。打开一个文件并编写内容。困难是什么?谢谢,没问题!如果您愿意,您可以通过单击投票跟踪器下方的复选标记来接受答案。对所有的反对票也很抱歉。。。stackoverflow有时会有点敌意!