python爬虫学习第八天
来源:互联网 发布:诛仙手游破凶辅助软件 编辑:程序博客网 时间:2024/05/24 07:25
今天学习完了requests.get(),requests.post()以及requests的其他一些基础功能
大体内容就是给get/post请求添加头信息,以及验证返回结果的状态(200/404)
练习8 不传递头信息,就不能正常请求某些网页(实际上是许多网页)
# import requests# r = requests.get('https://www.zhihu.com/explore')# print(r.text)
练习9 传递头信息,正常获取了网页内容
# import requests# headers = {# 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'# }# r = requests.get('https://www.zhihu.com/explore',headers=headers)# print(r.text)
练习10 post方法
# import requests# data = {# 'name': 'germey', 'age': '22'# }# r = requests.post('http://httpbin.org/post',data=data)# print(r.text)
练习11 r的其他属性
# import requests# r = requests.get('http://www.jianshu.com')# print(type(r.status_code),r.status_code)# print(type(r.headers),r.headers)# print(type(r.cookies),r.cookies)# print(type(r.url),r.url)# print(type(r.history),r.history)
练习12 requests.codes
# import requests# r = requests.get('http://www.jianshu.com')# exit() if not r.status_code==requests.codes.ok else print('successful!')
阅读全文
0 0
- python爬虫学习第八天
- python学习---第八天
- python爬虫学习第十八天
- python爬虫学习第二十八天
- python爬虫学习第三十八天
- Python快速学习第八天
- Python学习日记 第八天 EX18-19
- Python第八天
- 初学Python第八天
- python爬虫学习第一天
- python爬虫学习第三天
- python爬虫学习第五天
- python爬虫学习第七天
- python爬虫学习第九天
- python爬虫学习第十四天
- python爬虫学习第一节课
- 程序学习第八天
- 学习的第八天
- Class类
- 32. Longest Valid Parentheses
- MySQL中子查询IN,EXISTS,ANY,ALL,SOME,UNION介绍
- $.ajax中contentType: “application/json” 的用法
- 网络搭建
- python爬虫学习第八天
- 【CodeForces
- Java基础 —— 原生数据类型与包装类
- [Visual Studio]MFC游戏开发之回合制对战系统二_by书訢
- Ajax的Result工具类
- oracle函数与条件表达式
- JQuery入门(一)
- 浏览器对象模型BOM
- 二维前缀和 codeforces 832C