zoukankan      html  css  js  c++  java
  • requests模块(get请求)篇

    - HTTP for Humans,更简洁更友好
    - 继承了urllib的所有特征
    - 底层使用的是urllib3
    - 开源地址: https://github.com/requests/requests
    - 中文文档: http://docs.python-requests.org/zh_CN/latest/index.html
    - 安装: conda install requests

    - get请求
    - requests.get(url)
    - requests.request("get", url)
    - 可以带有headers和parmas参数

     案例一:

    import requests

    url = "http://www.baidu.com"

    # 两种请求方式
    # 使用get请求
    rsp = requests.get(url)
    print(rsp.text)


    # 使用request请求
    rsp = requests.request("get",url)
    print(rsp.text)

    运行结果如下:

    案例二:


    '''
    使用参数headers和params
    研究返回结果

    '''

    import requests

    url = "http://www.baidu.com/s?"

    kw = {
    "wd": "好人"
    }

    headers = {
    "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
    }

    rsp = requests.get(url,params=kw,headers=headers)

    # print(rsp.text)
    # print(rsp.content)
    print(rsp.url)
    print(rsp.encoding)
    print(rsp.status_code)

    运行结果如下:

  • 相关阅读:
    2013国内IT行业薪资对照表【技术岗位】
    Eclipse查看子类
    whereis 查找命令全路径
    开张了
    Ruby1.8中单行字符串写在多行
    FEMTO是什么
    FUSE文件系统
    魔兽私服pvpgn搭建
    linux网络源码分析(1)
    freehosting申请空间和ssh D设置
  • 原文地址:https://www.cnblogs.com/jerryspace/p/9851361.html
Copyright © 2011-2022 走看看