基本爬虫
import urllib.request as reqimport urllib.parse as parseimport sslimport jsonimport timessl._create_default_https_context = ssl._create_unverified_contexturl = 'https://api-yqzy.mrnaive.com/?s=App.MyUser.GetUserList'# 打开一个 URL , 获得一个 URL 资源data = { 'sign': 'cf1cbd2e142667516d34d570a616ce4b', 'page': 1, 'pageNum': 5,}head = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 ' 'Safari/537.36'}while True: # 将Unicode 资源编码成 utf-8 dataRes = parse.urlencode(data).encode('utf-8') # request 对象 requestObj = req.Request(url, dataRes, headers = head) openReq = req.urlopen(requestObj) # 返回的内容 , 将指定编码解码成 Unicode , 同时将json 转换成字典 res = json.loads(openReq.read().decode('utf-8')) print(requestObj.headers) print('结果:', res) # print('返回的类型:', type(res)) # 访问地址 print('访问地址:', openReq.geturl()) # 响应头 print('服务器信息:', openReq.info()) # http 状态码 print('http 状态码', openReq.getcode()) time.sleep(1)