py 爬虫 requests库 用法(一)//源码
来源:互联网 发布:四大文明古国 知乎 编辑:程序博客网 时间:2024/06/05 04:13
In [4]:
print(“hello”)
hello
In [3]:
import requests
import urllib
In [7]:
print(1+2)
3
测试¶
In [17]:
import requests
res=requests.get(“http://httpbin.org/get“)
print(res.text)
{
“args”: {},
“headers”: {
“Accept”: “/“,
“Accept-Encoding”: “gzip, deflate”,
“Connection”: “close”,
“Host”: “httpbin.org”,
“User-Agent”: “python-requests/2.14.2”
},
“origin”: “61.183.192.18”,
“url”: “http://httpbin.org/get”
}
In [31]:
import requests
import json
data={
“username”:”zcc”,
“password”:”12580”,
}
res=requests.get(“http://httpbin.org/get“,params=data)
print(res.text)
print(res.json())
print(json.loads(res.text))
{
“args”: {
“password”: “12580”,
“username”: “zcc”
},
“headers”: {
“Accept”: “/“,
“Accept-Encoding”: “gzip, deflate”,
“Connection”: “close”,
“Host”: “httpbin.org”,
“User-Agent”: “python-requests/2.14.2”
},
“origin”: “61.183.192.18”,
“url”: “http://httpbin.org/get?username=zcc&password=12580”
}
{‘args’: {‘password’: ‘12580’, ‘username’: ‘zcc’}, ‘headers’: {‘Accept’: ‘/‘, ‘Accept-Encoding’: ‘gzip, deflate’, ‘Connection’: ‘close’, ‘Host’: ‘httpbin.org’, ‘User-Agent’: ‘python-requests/2.14.2’}, ‘origin’: ‘61.183.192.18’, ‘url’: ‘http://httpbin.org/get?username=zcc&password=12580‘}
{‘args’: {‘password’: ‘12580’, ‘username’: ‘zcc’}, ‘headers’: {‘Accept’: ‘/‘, ‘Accept-Encoding’: ‘gzip, deflate’, ‘Connection’: ‘close’, ‘Host’: ‘httpbin.org’, ‘User-Agent’: ‘python-requests/2.14.2’}, ‘origin’: ‘61.183.192.18’, ‘url’: ‘http://httpbin.org/get?username=zcc&password=12580‘}
文件操作¶
In [2]:
import requests
res=requests.get(“http://logo.www.sogou.com/images/logo2014/new/favicon.ico“);
print(res.content)
with open(‘favin.ico’,’wb’)as s:
s.write(res.content)
s.close
状态码¶
In [28]:
import requests
response=requests.get(“http://www.baidu.com“)
exit() if not response.status_code ==200 else print(“request successfully!”)
request successfully!
cookie¶
In [38]:
import requests
res=requests.get(“http://www.baidu.com“)
for key ,value in res.cookies.items():
print(key+”=”+value)
BDORZ=27315
- py 爬虫 requests库 用法(一)//源码
- Python爬虫利器一之Requests库的用法
- Python爬虫利器一之Requests库的用法
- Python爬虫利器一之Requests库的用法
- Python 3爬虫网易云(一)—— Requests库用法
- Python利用Requests库写爬虫(一)
- Python从零开始写爬虫(一)requests库使用
- python3爬虫(一)requests库的学习
- Python利用Requests库写爬虫(一)
- 爬虫知识点(requests库)
- Python 网络爬虫与信息获取(一)—— requests 库的网络爬虫
- Python篇----Requests获取网页源码(爬虫基础)
- Python篇----Requests获取网页源码(爬虫基础)
- python爬虫系列(2)—— requests和BeautifulSoup库的基本用法
- python爬虫(requests)库安装
- Python爬虫入门(二)requests库
- 爬虫基础----requests库
- requests库---网络爬虫
- SQL全书总结——简洁版
- 5G:关键技术介绍
- Linux下主机信息查询
- 最简单的VS2015配置OpenGL开发环境方法
- SDUT-3403
- py 爬虫 requests库 用法(一)//源码
- Android聊天室输入框之仿微信加号按钮实现
- DNS的相关知识
- 文章标题
- computed属性和watch属性的区别之三【购物车之watch】
- web.xml详解
- Respberry Pi Firefox 中文设置
- 初步了解Ethereal/Wireshark 软件
- Http Header status