request¶
build_opener()¶
-
urllib.request.
build_opener
([handler, ...])¶ handler -
urllib.request.BaseHandler()
Возвращает объект для запросов
urllib.request.OpenerDirector()
proxy_handler = urllib.request.ProxyHandler({'http': proxy_http_url}) auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password( realm='Application', uri=uri, user=user, passwd=passwd ) opener = urllib.request.build_opener(auth_handler, proxy_handler) urllib.request.install_opener(opener) urllib.request.urlopen(login_url)
install_opener()¶
-
urllib.request.
install_opener
(opener)¶ Устанавливает глобальный объект для запросов.
Объектов может быть любой класс, реализующий методы
urllib.request.OpenerDirector()
opener = urllib.request.build_opener(auth_handler) urllib.request.install_opener(opener)
urlopen()¶
-
urllib.request.
urlopen
(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=None, context=None)¶ Выполняет запрос и возвращает результат ответа с сервера в виде объекта
http.client.HTTPResponse
conn = urlopen(url) conn = urlopen(Request(url)) with urlopen(url) as f: print(f.read()) # b'html content' req = Request(url=url, data=b'This data is passed to stdin of the CGI') with urllib.request.urlopen(req) as f: print(f.read().decode('utf-8')) Got Data: "This data is passed to stdin of the CGI"
AbstractBasicAuthHandler()¶
AbstractDigestAuthHandler()¶
BaseHandler()¶
HTTPBasicAuthHandler()¶
- class
urllib.request.
HTTPBasicAuthHandler
(password_mgr=None)¶ auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password( realm='Application', uri=uri, user=user, passwd=passwd ) opener = urllib.request.build_opener(auth_handler) urllib.request.install_opener(opener) urllib.request.urlopen(login_url)
-
http_error_401
(req, fp, code, msg, hdrs)¶
-
HTTPCookieProcessor()¶
-
urllib.request.
HTTPCookieProcessor
(cookijar=None)¶ http.cookiejar.Cookiejar()
HTTPDigestAuthHandler()¶
HTTPErrorProcessor()¶
HTTPPasswordMgr()¶
HTTPPasswordMgrWithDefaultRealm()¶
HTTPPasswordMgrWithPriorAuth()¶
HTTPRedirectHandler()¶
OpenerDirector()¶
ProxyBasicAuthHandler()¶
ProxyDigestAuthHandler()¶
ProxyHandler()¶
- class
urllib.request.
ProxyHandler
¶ proxy_handler = urllib.request.ProxyHandler({'http': proxy_http_url})
-
<protocol>_open(req)
-
Request()¶
- class
urllib.request.
Request
(url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None)¶ url - str
data - bytes
query_args = {'q': 'text'} req = Request(url) req = Request( url, data=urllib.parse.urlencode(query_args).encode('utf-8') )
-
data
¶
-
full_url
¶
-
host
¶
-
origin_req_host
¶
-
selector
¶
-
type
¶
-
unverifiable
¶
-
add_header
(key, value)¶ req.add_header('User-agent', 'ChromeBrowser')
-
add_unredirected_header
()¶
-
get_full_url
()¶
-
get_header
(key, default=None)¶
-
get_method
()¶
-
has_header
(header)¶
-
header_items
()¶
-
remove_header
(header)¶
-
set_proxy
(host, type)¶