zoukankan      html  css  js  c++  java
  • python3 get和post

    post:

    from urllib.error import URLError,HTTPError  
    import urllib.request  
    import urllib.parse  
    url='http://www.wunderground.com/cgi-bin/findweather/getForecast'  
    values={'query':'10001'}  
    url_values=urllib.parse.urlencode(values)  
        #print(url_values)        
    url_values=url_values.encode(encoding='UTF8')  
    full_url=urllib.request.Request(url,url_values)
    try:  
        response=urllib.request.urlopen(full_url)   #open=urlopen
        data=response.read()
        print(data)
    except HTTPError as e:  
        print('Error code:',e.code)   
    except URLError as e:  
        print('Reason',e.reason)  
        the_page=response.read()  
        print(the_page)

    get:

    from urllib.error import URLError,HTTPError  
    import urllib.request  
    import urllib.parse  
    url='http://www.wunderground.com/cgi-bin/findweather/getForecast'  
    values={'query':'10001'}  
    url_values=urllib.parse.urlencode(values)
    newUrl=url+'?'+url_values
    print(newUrl)
    try:  
        response=urllib.request.urlopen(newUrl)   #open=urlopen
        data=response.read()
        print(data)
    except HTTPError as e:  
        print('Error code:',e.code)   
    except URLError as e:  
        print('Reason',e.reason)  
        the_page=response.read()  
        print(the_page)
  • 相关阅读:
    C#创建ActiveX
    easy-ui 中的事件触发 (tree)
    程序目录
    微信公众平台开发
    Redis分片机制
    Redis主从切换
    Redis主从复制
    Redis持久化机制
    Redis缓存击穿、缓存穿透、缓存雪崩
    Redis与数据库数据一致性
  • 原文地址:https://www.cnblogs.com/sklww/p/3782265.html
Copyright © 2011-2022 走看看