2019年12月16日 星期一

print(dir(urllib.request.urlopen(url))) 實作



import urllib.request

url = 'http://www.baidu.com/'

response = urllib.request.urlopen(url)

print(type(response))
print(dir(response))
print(dir(urllib.request.urlopen(url)))

-------------------------------------------------------------------------------------------------------

<class 'http.client.HTTPResponse'>
['__abstractmethods__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_abc_cache', '_abc_negative_cache', '_abc_negative_cache_version', '_abc_registry', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_check_close', '_close_conn', '_get_chunk_left', '_method', '_peek_chunked', '_read1_chunked', '_read_and_discard_trailer', '_read_next_chunk_size', '_read_status', '_readall_chunked', '_readinto_chunked', '_safe_read', '_safe_readinto', 'begin', 'chunk_left', 'chunked', 'close', 'closed', 'code', 'debuglevel', 'detach', 'fileno', 'flush', 'fp', 'getcode', 'getheader', 'getheaders', 'geturl', 'headers', 'info', 'isatty', 'isclosed', 'length', 'msg', 'peek', 'read', 'read1', 'readable', 'readinto', 'readinto1', 'readline', 'readlines', 'reason', 'seek', 'seekable', 'status', 'tell', 'truncate', 'url', 'version', 'will_close', 'writable', 'write', 'writelines']
['__abstractmethods__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_abc_cache', '_abc_negative_cache', '_abc_negative_cache_version', '_abc_registry', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_check_close', '_close_conn', '_get_chunk_left', '_method', '_peek_chunked', '_read1_chunked', '_read_and_discard_trailer', '_read_next_chunk_size', '_read_status', '_readall_chunked', '_readinto_chunked', '_safe_read', '_safe_readinto', 'begin', 'chunk_left', 'chunked', 'close', 'closed', 'code', 'debuglevel', 'detach', 'fileno', 'flush', 'fp', 'getcode', 'getheader', 'getheaders', 'geturl', 'headers', 'info', 'isatty', 'isclosed', 'length', 'msg', 'peek', 'read', 'read1', 'readable', 'readinto', 'readinto1', 'readline', 'readlines', 'reason', 'seek', 'seekable', 'status', 'tell', 'truncate', 'url', 'version', 'will_close', 'writable', 'write', 'writelines']

-------------------------------------------------------------------------------------------------------------

>>> print(help(response.url))
No Python documentation found for 'http://www.baidu.com/'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

None
>>> print(help(response.info))
Help on method info in module http.client:

info() method of http.client.HTTPResponse instance
    Returns an instance of the class mimetools.Message containing
    meta-information associated with the URL.

    When the method is HTTP, these headers are those returned by
    the server at the head of the retrieved HTML page (including
    Content-Length and Content-Type).

    When the method is FTP, a Content-Length header will be
    present if (as is now usual) the server passed back a file
    length in response to the FTP retrieval request. A
    Content-Type header will be present if the MIME type can be
    guessed.

    When the method is local-file, returned headers will include
    a Date representing the file's last-modified time, a
    Content-Length giving file size, and a Content-Type
    containing a guess at the file's type. See also the
    description of the mimetools module.

None
>>> print(response.info)
<bound method HTTPResponse.info of <http.client.HTTPResponse object at 0x0000019A39B707B8>>
>>> print(response.url)
http://www.baidu.com/

>>>





沒有留言:

張貼留言

print(dir(urllib.request.urlopen(url))) 實作

import urllib.request url = 'http://www.baidu.com/' response = urllib.request.urlopen(url) print(type(response)) print(dir(...