zoukankan      html  css  js  c++  java
  • Requests属性

    一、解析json

     response=requests.get('http://httpbin.org/get')
    
     import json
     res1=json.loads(response.text) #太麻烦
    
    res2=response.json() #直接获取json数据
    
    print(res1 == res2) #True

    二、使用代理

    #官网链接: http://docs.python-requests.org/en/master/user/advanced/#proxies
    
    #ip 代理收费(通过代理访问自己的服务,在服务端取出客户端ip查看一下)
    # import requests
    # proxies={
    #     'http':'http://egon:123@localhost:9743',#带用户名密码的代理,@符号前是用户名与密码
    #     'http':'http://localhost:9743',
    #     'https':'https://localhost:9743',
    #     'http':'http://124.205.155.148:9090'
    # }
    # respone=requests.get('https://www.12306.cn',
    #                      proxies=proxies)
    #
    # print(respone.status_code)

    三、超时设置

    #两种超时:float or tuple
    #timeout=0.1 #代表接收数据的超时时间
    #timeout=(0.1,0.2)#0.1代表链接超时  0.2代表接收数据的超时时间
    
    import requests
    respone=requests.get('https://www.baidu.com',
                         timeout=0.0001)

    四、上传文件

    import requests
    files={'file':open('a.jpg','rb')}
    respone=requests.post('http://httpbin.org/post',files=files)
    print(respone.status_code)
  • 相关阅读:
    数据库设计
    Android入门
    Java
    深入理解计算机
    Python
    JS
    powerdesigner
    计算机程序员+研一生活总结
    影视剧里程序员使用的双显示屏,在生活中真的需要么?
    性质太恶劣,紧张时期竟有人开发假冒健康码软件,幸已下架!
  • 原文地址:https://www.cnblogs.com/xiongying4/p/11935502.html
Copyright © 2011-2022 走看看