zoukankan      html  css  js  c++  java
  • python3 urllib.request.Request的用法

    import urllib.request
    import urllib.parse

    url = 'http://127.0.0.1:8000/api/login/'
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
    headers['Host'] = 'httpbin.org'
    dict = {'user': 'admin','pwd': '12345',}

    data = urllib.parse.urlencode(dict).encode('utf-8')
    #data参数如果要传必须传bytes(字节流)类型的,如果是一个字典,先用urllib.parse.urlencode()编码。
    request = urllib.request.Request(url = url,data = data,headers = headers,method = 'POST')

    response = urllib.request.urlopen(request)
    html = response.read().decode('utf-8')

    print(html)
    ————————————————
    版权声明:本文为CSDN博主「开开136」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/kaikai136412162/java/article/details/83142711

  • 相关阅读:
    Mac + Python3 安装scrapy
    Pyqt4+Eric6+python2.7.13(windows)
    js基础⑥
    python模块之os,sys
    Python模块之random
    Python模块之PIL
    js基础⑤
    js基础④
    js基础③
    centOS目录结构详细版
  • 原文地址:https://www.cnblogs.com/zhoading/p/12689165.html
Copyright © 2011-2022 走看看