查看“Python requests库的使用”的源代码
←
Python requests库的使用
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==requests库概述== 中文版概述: http://docs.python-requests.org/zh_CN/latest/ 英文版概述: http://docs.python-requests.org/zh_CN/latest/ ==安装resuests库== *执行命令: pip3 install requests *具体安装方法,可参考[[Python第三方库的安装]] ==requests库的用法== *常用用法: <nowiki>>>> import requests >>> r = requests.get("http://www.baidu.com")#打开一个网页 >>> print(r.status_code) #返回状态 200 >>> print(r.text) #观察返回的内容 '<!DOCTYPE html>\r\n<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>ç\x99¾åº¦ä¸\x80ä¸\x8bï¼\x8cä½\xa0å°±ç\x9f¥é\x81\x93</title></head> ... >>>r.encoding #查看编码方式,因为是这种,所以乱码 'ISO-8859-1' >>> r.encoding = 'utf-8' >>> print(r.text) '<!DOCTYPE html>\r\n<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head></nowiki> 返回 [[Python网络爬虫和自动化]]
返回至
Python requests库的使用
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息