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)

    运行结果如下:

  • 相关阅读:
    Codeforces 451A Game With Sticks
    POJ 3624 Charm Bracelet
    POJ 2127 Greatest Common Increasing Subsequence
    POJ 1458 Common Subsequence
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1698
    HDU 1754
    POJ 1724
    POJ 1201
    CSUOJ 1256
  • 原文地址:https://www.cnblogs.com/jerryspace/p/9851361.html
Copyright © 2011-2022 走看看