爬虫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()

>>> print(response.info())

>>> response.getcode()
200
>>>

转载于:https://www.cnblogs.com/gdy123/p/9807747.html

你可能感兴趣的:(爬虫day1)