python3
encoding(‘utf-8’)
导入
import urllib.request
get请求 读取html内容
f=urllib.request.urlopen(‘http://jingyan.baidu.com/article/455a9950bc94b8a166277898.html‘)
response=f.read()
print(‘—–response——’)
print(str(response))
print(f.geturl())
print(f.getcode())
读取图片并保存
urllib.request.urlretrieve(‘http://hiphotos.baidu.com/exp/pic/item/5beeba0f4bfbfbed25bd434d7ff0f736aec31fd8.jpg‘)
将图片保存到固定位置
urllib.request.urlretrieve(‘http://hiphotos.baidu.com/exp/pic/item/5beeba0f4bfbfbed25bd434d7ff0f736aec31fd8.jpg‘,filename=’E:/a.png’)