標籤:sel 資訊 fragment headers open false urllib2 after dir
1、urlopen(url, data, timeout)
第一個參數url即為URL,第二個參數data是訪問URL時要傳送的資料,第三個timeout是設定逾時時間。第二三個參數是可以不傳送的,data預設為空白None,timeout預設為 socket._GLOBAL_DEFAULT_TIMEOUT第一個參數URL是必須要傳送的,在這個例子裡面我們傳送了百度的URL,執行urlopen方法之後,返回一個response對象,返回資訊便儲存在這裡面。
2、Request:
Request類的執行個體,構造時需要傳入Url,Data等等的內容
class Request: def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False): # unwrap(‘<URL:type://host/path>‘) --> ‘type://host/path‘ self.__original = unwrap(url) self.__original, self.__fragment = splittag(self.__original) self.type = None # self.__r_type is what‘s left after doing the splittype self.host = None self.port = None self._tunnel_host = None self.data = data self.headers = {} for key, value in headers.items(): self.add_header(key, value) self.unredirected_hdrs = {} if origin_req_host is None: origin_req_host = request_host(self) self.origin_req_host = origin_req_host self.unverifiable = unverifiable
urllib2功能說明