网络编程

  1. import urllib.request as request
  2. url = "https://v.api.aa1.cn/api/pyq/index.php"
  3. req = request.Request(url)
  4. with request.urlopen(req) as response:
  5. data = response.read().decode()
  6. print(data)

json

  • load 将文件数据转为python对象
  • loads 将内存数据转换为python对象

json.load(open('file.json','r'))

  • dump 将dict转换为json字符串保存到文件中
  • dumps 将dict转换为json字符串