http://docs.python-requests.org/zh_CN/latest/user/quickstart.html  ,官方文档。自己有空看看顺便敲两下熟悉一下。

还有别把文件放的太深。这个idle 识别不了,悲催的很。

import requests
response = requests.get('https://www.baidu.com') print (type(response))
print (response.status_code)
print (type(response.text))
print (response.text)
print (response.cookies)
print (response.content)
print (response.content.decode('utf-8'))

发送请求:

  现在,我们有一个名为 r 的 Response 对象。我们可以从这个对象中获取所有我们想要的信息。

import requests

r= requests.get('https://github.com/timeline.json')

Requests 简便的 API 意味着所有 HTTP 请求类型都是显而易见的。例如,你可以这样发送一个 HTTP POST 请求

r = requests.post("http://httpbin.org/post")
r = requests.put("http://httpbin.org/put")
r = requests.delete("http://httpbin.org/delete")
r = requests.head("http://httpbin.org/get")
r = requests.options("http://httpbin.org/get")

全部摘抄的request的官方文档

你也许经常想为 URL 的查询字符串(query string)传递某种数据。如果你是手工构建 URL,那么数据会以键/值对的形式置于 URL 中,跟在一个问号的后面。例如,httpbin.org/get?key=val。 Requests 允许你使用 params 关键字参数,以一个字符串字典来提供这些参数。举例来说,如果你想传递 key1=value1 和 key2=value2 到httpbin.org/get ,那么你可以使用如下代码:

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.get("http://httpbin.org/get", params=payload)
import requests
data = {
"name":"zhaofan",
"age":22
}
response = requests.get("http://httpbin.org/get",params=data)
print(response.url)
print(response.text)

requests 简单应用的更多相关文章

  1. python第三方库requests简单介绍

    一.发送请求与传递参数 简单demo: import requests r = requests.get(url='http://www.itwhy.org') # 最基本的GET请求 print(r ...

  2. 使用requests简单的页面爬取

    首先安装requests库和准备User Agent 安装requests直接使用pip安装即可 pip install requests 准备User Agent,直接在百度搜索"UA查询 ...

  3. requests简单应用

    requests发送get请求 无参数的get请求: response = requests.get(url='http://ws.webxml.com.cn/WebServices/WeatherW ...

  4. Python第三方模块--requests简单使用

    1.requests简介 requests是什么?python语言编写的,基于urllib的第三方模块 与urllib有什么关系?urllib是python的内置模块,比urllib更加简洁和方便使用 ...

  5. python requests 简单实现易班登录,自动点赞,评论,发表

    小编能力有限,本文纯属瞎编,如有雷同,你去打辅导员涩 一.前戏 有个操蛋,操蛋,操蛋的辅导员促使小编成长,原因:易班需要活跃度,辅导员安排班上每个人必须去易班上 写文章,写评论,发投票...  我觉得 ...

  6. python requests简单接口自动化

    get方法 url:显而易见,就是接口的地址url啦 headers:定制请求头(headers),例如:content-type = application/x-www-form-urlencode ...

  7. Python爬虫从入门到进阶(3)之requests的使用

    快速上手(官网地址:http://www.python-requests.org/en/master/user/quickstart/) 发送请求 首先导入Requests模块 import requ ...

  8. Requests库使用总结

    概述 Requests是python中一个很Pythonic的HTTP库,用于构建HTTP请求与解析响应 Requests开发哲学 Beautiful is better than ugly.(美丽优 ...

  9. Python爬虫:requests 库详解,cookie操作与实战

    原文 第三方库 requests是基于urllib编写的.比urllib库强大,非常适合爬虫的编写. 安装: pip install requests 简单的爬百度首页的例子: response.te ...

随机推荐

  1. python 获取exception 名字

    def func(): list = [] usr = input('username:') pwd = input('password:') try: list[4] # 这个是调用不了的,因为列表 ...

  2. python的语法规范及for和while

    1.缩进: 空白在Python中是重要的.事实上行首的空白是重要的.它称为缩进.在逻辑行首的空白(空格和制表符)用来决定逻辑行的缩进层次,从而用来决定语句的分组.这意味着同一层次的语句必须有相同的缩进 ...

  3. 007-搭建框架-开发AOP框架

    一.代码地址 https://github.com/bjlhx15/smart-framework.git 二.代码编写 2.1.定义切面注解 增加Aspect注解 package com.lhx.s ...

  4. PyNest——part 2: populations of neurons

    part 2: populations of neurons introduction 在这篇讲义中,我们着眼于创建和参数化神经元批次,并将它们连接起来. 当你完成这些材料时,你会知道如何: 创建具有 ...

  5. spring task定时器的配置使用

    spring task的配置方式有两种:配置文件配置和注解配置. 1.配置文件配置 在applicationContext.xml中增加spring task的命名空间: xmlns:task=&qu ...

  6. boost之智能指针

    内存问题永远是c++中讨论的重要话题 1.c98 auto_ptr的实现,auto_ptr的特点是始终只保持一个指针指向对象,若经过赋值或者拷贝之后原指针失效 #include <iostrea ...

  7. Django of python 中文文档 及debug tool

    http://python.usyiyi.cn/django/index.html http://www.ziqiangxuetang.com/django/django-views-urls.htm ...

  8. 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related(转)

    转至:http://www.cnblogs.com/taoys/archive/2010/12/30/1922186.html application/x-www-form-urlencoded: 窗 ...

  9. vim常用快捷键记录

    yy复制一行 2yy复制2行 同理 3yy复制3行 p粘贴复制 dd删除一行 ctrl+f 翻页 ctrl+b 上翻 shift+a 跳到行尾进入insert模式 shift+i 跳到行首进入inse ...

  10. win32调试——OutputDebugString

    win32下开发console程序可以直接用printf打印到控制台. 开发图形界面程序时,可以调用OutputDebugString将字符串输出到Debug窗口, 注意是要调试运行才能看到Debug ...