爬虫day1

别来无恙 提交于 2019-11-27 13:47:58

一、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
>>>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!