最近粉上花花,感觉这个姑娘的笑容很治愈啊。于是想下一些写真。在豆瓣相册和贴吧找到了比较全的《转调》。这几天老是被导师指派去写文档,出差什么的。艰苦的生活需要治愈啊。代码贴上了,喜欢花花的自己去下吧。
import requests
from bs4 import BeautifulSoup
import time
import datetime
fetch = [18*x for x in range(6)]
page = map(str,fetch)
urls = map(lambda x: "https://www.douban.com/photos/album/1622970129/?start="+x,page)
imglist = []
for url in urls:
html = requests.get(url)
htmltext = html.text
soup=BeautifulSoup(htmltext,"lxml")
imgs = soup.find_all("a",class_="photolst_photo")
for each in imgs:
imgurl = each.img['src']
imglist.append(imgurl)
i = 0
for each in imglist:
try:
pic = requests.get(each)
except requests.exceptions.ConnectionError:
print(each)
continue
filename = str(i) + ".jpg"
fp = open(filename,'wb')
fp.write(pic.content) #写入图片
fp.close()
print(str(i)+"下载成功")
i = i +1
print(len(imglist))