Discuss / Python / work 2333

work 2333

Topic source

Phioton

#1 Created at ... [Delete] [Delete and Lock User]

用了前面楼层同学给的地址

# -*- coding: utf-8 -*-
from urllib import request
import json

def fetch_data(url):
    with request.urlopen(str(url)) as f:
        data = f.read().decode('utf-8')
        return json.loads(data)


# 测试
URL = 'https://yesno.wtf/api'
data = fetch_data(URL)
print(data)
assert data['answer']== 'yes' and (data['forced']== False)
print('ok')

  • 1

Reply