urllib2功能說明

來源:互聯網
上載者:User

標籤: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功能說明

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.