爬虫day1
一、urllib
import urllib.request
response= urllib.request.urlopen("")
html=response.read()
print(html)
utf-8解码
html = html.decode("utf-8")
print(html)
二、实战一 下载一只猫
import urllib.request
response = urllib.request.urlopen('http://placekitten.com/g/600/700')
#=req=urllib.request.Request('http://placekitten.com/g/600/700')
#response=urllib.request.urlopen(req)
cat_img = response.read()
with open('cat_600_700.jpg','wb')as f:
f.write(cat_img)
三个查询函数. geturl() info() getcode()
>>> response.geturl()
'http://placekitten.com/g/600/700'
>>> response.info()
<http.client.HTTPMessage object at 0x0000027B8D8FC898>
>>> print(response.info())
>>> response.getcode()
200
>>>