标签:port lib 爬取 python 步骤 file amp size 打开
import urllib.request image_url=‘https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569075968903&di=6e275342eb912831affe1c2f5511e05d&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F14c272157c7345f33bab613327d7ee11a8b2c5344ea1a-rSck09_fw658‘ # 方法一: urllib.request.urlretrieve(image_url,‘chun.jpg‘) # 方法二: response=urllib.request.urlopen(image_url) file=open(r‘E:\qing.jpg‘,‘wb‘)# 二进制格式,wb二进制格式写入 file.write(response.read()) file.close()
#方法三: with open(‘qing.jpg‘,‘wb‘) as fp: fp.write(response.read())
import urllib.request url=‘http://www.baidu.com‘ response=urllib.request.urlopen(url=url) print(response.readlines()) print(dict(response.getheaders())) print(response.read().decode()) with open(‘baidu.html‘,‘w‘,encoding=‘utf8‘)as fp: fp.write(response.read().decode())
with open(r‘E:\qing.jpg‘,‘wb‘) as fp:# wb以二进制字节进行读写 fp.write(response.read())
file=open(r‘E:\qing.jpg‘,‘wb‘) file.write(url) file.close()
标签:port lib 爬取 python 步骤 file amp size 打开
原文地址:https://www.cnblogs.com/ybl20000418/p/11564425.html