zoukankan      html  css  js  c++  java
  • python-网络编程urllib模块

    一、操作网络发送请求

    from urllib.request import urlopen   #发送请求

    from urllib.parse import urlencode   #用来把字典形式转换成k=v形式;username = dusir&pwd = 123456

    ####get请求

    url='http://127.0.0.1:/8000/login'

    url1='http://127.0.0.1:/8000/login?usernanme = gongzai&pwd = 1234556'

    res = urlopen(url+'?'usernanme = gongzai&pwd = 1234556').read().decode()   

    res = urlopen(url)1.read()decode()

    # 请求默认返回的是bytes类型的所以要decode成str类型

    print(res)

    ####pos请求

    data ={"user_id":1,"price":"999"}

    res = urlopen(url,data.encode()).read().decode()   #需要先转成bytes在转成str

    param = urlencode(data) 是把字典转成k=v形式username=jmy1235&price=123456

    二、编码解码

    from urllib.parse import quote,unquote #  用来做url编码和解码

    eg.1:

    url = "http://www.fengniao.com/search.php?keyword=%C3%C0%C5%AE&charset=gbk"

    print(unquote(url))    #解码

    s = 'kkkk%ddt%ff'

    print(quote(s))  #编码

  • 相关阅读:
    bzoj [POI2015]Myjnie
    bzoj2217 [Poi2011]Lollipop
    Codeforces A Mist of Florescence
    bzoj4380 [POI2015]Myjnie
    bzoj4292 [PA2015]Równanie
    bzoj 3517翻硬币
    模块补充
    python解释器
    __file__、__name__、__dict__方法整理
    软件开发规范
  • 原文地址:https://www.cnblogs.com/lingxia/p/7889928.html
Copyright © 2011-2022 走看看