|
10鱼币
- import requests
- import json
- if __name__ == '__main__':
- url = 'https://fanyi.baidu.com/sug'
- heads = {
- 'User - Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 108.0.0.0Safari / 537.36'
- }
- date = {
- 'kw':'dog'
- }
- response = requests.post(url=url,data=date,headers=heads)
- json_date = response.json()
- print(json_date)
- filename = "dog.json"
- myfile = open(filename,mode='w',encoding='utf-8')
- json.dump(obj=json_date,fp=myfile,ensure_ascii=False)
复制代码
为什么我这个不能永久储存为文件格式
我怀疑是你的工作目录的问题,你执行的工作目录不是你认为的那个文件夹,
我帮你加了几行代码,你执行一下看看:
- import requests
- import json
- if __name__ == '__main__':
- url = 'https://fanyi.baidu.com/sug'
- heads = {
- 'User - Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 108.0.0.0Safari / 537.36'
- }
- date = {
- 'kw':'dog'
- }
- response = requests.post(url=url,data=date,headers=heads)
- json_date = response.json()
- print(json_date)
- filename = "dog.json"
- myfile = open(filename,mode='w',encoding='utf-8')
- json.dump(obj=json_date,fp=myfile,ensure_ascii=False)
-
- # 新加的代码
- import os
- cwd = os.getcwd()
- print(f'当前工作目录为:{cwd},正在为你打开当前工作目录')
- os.startfile(cwd)
复制代码
|
最佳答案
查看完整内容
我怀疑是你的工作目录的问题,你执行的工作目录不是你认为的那个文件夹,
我帮你加了几行代码,你执行一下看看:
|