码迷,mamicode.com
首页 > 其他好文 > 详细

网络编程

时间:2018-05-18 13:51:33      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:xxx   use   内容   网络   json   inf   username   coding   open   

from urllib import request,parse
url=‘http://www.xxx.cn‘
req=request.urlopen(url) #打开一个url,发get请求
content=req.read().decode()
fw=open(‘baidu.html‘,‘w‘,encoding=‘utf-8‘)
fw.write(content)

# 网络爬虫,从其他的网站上,获取一些有用的内容

import json
url=‘http://api.xxx.xx/api/user/stu_info?stu_name=xxx‘
req=request.urlopen(url)
content=req.read().decode()
res_dic=json.loads(content)
if res_dic.get(‘error_code‘)==0:
print(‘测试通过‘)
else:
print(‘测试失败‘,res_dic)


url=‘http://api.xxx.xx/api/user/lxxin‘
data={
‘username‘:‘xxxxxxx‘,
‘passwd‘:‘aA123456‘
}
data=parse.urlencode(data) #urlencode,自动给你拼好参数
req=request.urlopen(url,data.encode())
print(req.read().decode())

网络编程

标签:xxx   use   内容   网络   json   inf   username   coding   open   

原文地址:https://www.cnblogs.com/jiadan/p/9055178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!