python爬虫很基础的代码

from urllib.request import urlopen
response=urlopen("http://www.bing.com")
print(response.closed)
with response:
    print(1,type(response))
    print(2,response.status,response.reason)
    print(3,response.geturl())
    print(4,response.info())
    print(5,response.read())
print(response.closed)

False
1
2 200 OK
3 https://www4.bing.com/
4 Cache-Control: private, max-age=0
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Vary: Accept-Encoding
P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
Set-Cookie: SRCHD=AF=NOFORM; domain=.bing.com; expires=Sun, 18-Oct-2020 03:16:59 GMT; path=/
Set-Cookie: SRCHUID=V=2&GUID=563BF23C2B8E4FAFA8E8F93D689130E0&dmnchg=1; domain=.bing.com; expires=Sun, 18-Oct-2020 03:16:59 GMT; path=/
Set-Cookie: SRCHUSR=DOB=20181018; domain=.bing.com; expires=Sun, 18-Oct-2020 03:16:59 GMT; path=/
Set-Cookie: _SS=SID=3976EE776BBE6AD82F5DE2FB6A766BFA; domain=.bing.com; path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-MSEdge-Ref: Ref A: DD019EF78BDC4DA2AD57F4D8D35E3D63 Ref B: HK2EDGE1011 Ref C: 2018-10-18T03:16:59Z
Set-Cookie: _EDGE_S=F=1&SID=3976EE776BBE6AD82F5DE2FB6A766BFA; path=/; httponly; domain=bing.com
Set-Cookie: _EDGE_V=1; path=/; httponly; expires=Tue, 12-Nov-2019 03:16:59 GMT; domain=bing.com
Set-Cookie: MUID=1CB27CCA6DA56C75324170466C6D6DFF; path=/; expires=Tue, 12-Nov-2019 03:16:59 GMT; domain=bing.com
Set-Cookie: MUIDB=1CB27CCA6DA56C75324170466C6D6DFF; path=/; httponly; expires=Tue, 12-Nov-2019 03:16:59 GMT
Date: Thu, 18 Oct 2018 03:16:58 GMT
Connection: close


5 b'\xe5\xbe\xae\xe8\xbd\xaf Bing \xe6\x90\x9c\xe7\xb4\xa2 - \xe5\x9b\xbd\xe5\x86\x85\xe7\x89\x88

你可能感兴趣的:(python)