Python基础 访问网络资源 requests
来源:互联网 发布:网络基础技术视频教程 编辑:程序博客网 时间:2024/06/04 19:50
requests获取URL资源
Get 访问一个网页
运行示例
#!/usr/bin/env python3# -*- coding: utf-8 -*-# Python基础 访问网络资源 requests## Get 访问一个网页import requests# 访问百度result = requests.get("https://www.baidu.com")print(result.status_code)print(result.text)
运行结果
D:\PythonProject>python main.py200<!DOCTYPE html><!--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=https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.min.css><title>ç™¾åº¦ä¸€ä¸‹ï¼Œä½ å°±çŸ¥é“</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus=autofocus></sp....
获取Json对象
运行示例
#!/usr/bin/env python3# -*- coding: utf-8 -*-# Python基础 访问网络资源 requests# Get 访问一个网页import requests# 访问百度result = requests.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%202151330&format=json")#获取Json对象print(result.json())
运行结果
D:\PythonProject>python main.py{'query': {'count': 1, 'created': '2017-12-21T15:38:56Z', 'lang': 'en-US', 'results': {'channel': {'units': {'distance': 'mi', 'pressure': 'in', 'speed': 'mph', 'temperature': 'F'}, 'title': 'Yahoo! Weather - Beijing, Beijing, CN', 'link': 'http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2151330/', 'description': 'Yahoo! Weather for Beijing, Beijing, CN', 'language': 'en-us', 'lastBuildDate': 'Thu, 21 Dec 2017 11:38 PM CST', 'ttl': '60', 'location': {'city': 'Beijing', 'country': 'China', 'region': ' Beijing'}, 'wind': {'chill': '19', 'direction': '340', 'speed': '4'}, 'atmosphere': {'humidity': '63', 'pressure': '1018.0', 'rising': '0', 'visibility': '16.1'}, 'astronomy': {'sunrise': '7:33 am', 'sunset': '4:53 pm'}, 'image': {'title': 'Yahoo! Weather', 'width': '142', 'height': '18', 'link': 'http://
post 方法
运行示例
#!/usr/bin/env python3# -*- coding: utf-8 -*-# Python基础 访问网络资源 requests# Get 访问一个网页import requests# post 方法result = requests.post('https://accounts.douban.com/login', data={'form_email': 'abc@example.com', 'form_password': '123456'})#获取Json对象print(result)
运行结果
D:\PythonProject>python main.py<Response [200]>
用到了在细究即可,知道访问网络资源很方便即可
阅读全文
0 0
- Python基础 访问网络资源 requests
- python,requests基础
- java SE基础(URL访问网络资源)
- Python库Requests的基础使用
- python requests
- python requests
- Python Requests
- python Requests
- python Requests
- python requests
- Requests-Python
- python爬虫之requests对https的限制访问
- Python、requests模块使用代理服务器实现微博访问
- 无权限访问网络资源
- 使用URL访问网络资源
- 使用URL访问网络资源
- 访问Internet网络资源
- 使用URL访问网络资源
- javascript换行问题
- 数字图像处理,初识压缩感知Compressive Sensing
- cisco静态浮动路由详细配置
- Java实例-九九乘法表
- hdu 6237
- Python基础 访问网络资源 requests
- Oracle11g安装教程图解
- 2017.12.20练习
- Intel DPDK部署
- 创建一个Rectangle类,添加winth和height两个成员变量.........
- 解决 tensorflow softmax_cross_entropy_with_logits() 报错 Only call `softmax_cross_entropy_with_logits`
- Python文本数据处理
- 进程和线程关系及区别
- codeforce 899E