urllib2

作者: JaedenKil | 来源:发表于2017-12-02 05:27 被阅读7次
    import urllib2
    response = urllib2.urlopen('http://www.baidu.com')
    html = response.read()
    print html
    
    import urllib2
    req = urllib2.Request('http://www.baidu.com')
    response = urllib2.urlopen(req)
    page = response.read()
    print page
    
    import urllib
    import urllib2
    
    url = 'http://www.someserver.com/register.cgi'
    
    values = {
        'name': "Lord",
        'location': 'China',
        'language': 'Python'
    }
    data = urllib.urlencode(values)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    page = response.read()
    
    import urllib
    import urllib2
    
    data = {
        'name': 'Lord',
        'location': 'China',
        'language': 'Python'
    }
    values = urllib.urlencode(data)
    print values
    
    url = 'http://www.example.com/example.cgi'
    full_url = url + '?' + values
    data = urllib2.urlopen(full_url)
    

    相关文章

      网友评论

        本文标题:urllib2

        本文链接:https://www.haomeiwen.com/subject/jaygbxtx.html