码迷,mamicode.com
首页 > 编程语言 > 详细

【python】urllib2

时间:2014-07-22 23:08:32      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   os   io   

urllib2.urlopen(url[, data][, timeout])

Open the URL url, which can be either a string or a Request object.

data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format.

The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This actually only works for HTTP, HTTPS and FTP connections.

This function returns a file-like object with three additional methods:

  • geturl() — return the URL of the resource retrieved, commonly used to determine if a redirect was followed
  • info() — return the meta-information of the page, such as headers, in the form of an mimetools.Message instance (see Quick Reference to HTTP Headers)
  • getcode() — return the HTTP status code of the response
class urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable])

This class is an abstraction of a URL request.url should be a string containing a valid URL.

【python】urllib2,布布扣,bubuko.com

【python】urllib2

标签:des   style   http   color   os   io   

原文地址:http://www.cnblogs.com/ljygoodgoodstudydaydayup/p/3861318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!