爬取豆瓣推荐书籍页的图书的图片保存到本地
# -*- coding UTF-8 -*-
import re
import requests
import os
def getsite(url):
website=requests.get(url)
url="https://book.douban.com/tag/%E7%BC%96%E7%A8%8B"
website=requests.get(url)
links=re.findall("(https:\/\/img3.doubanio.com\/mpic\/(\w+\.jpg))",website.text)
dir="test/"
if not os.path.exists(dir):
os.makedirs(dir)
count=0
for link,name in links:
with open(dir+name,‘wb‘) as img:
file=requests.get(link)
img.write(file.content)
img.close()
count+=1
print("已抓取%s张图片"%(count))
原文地址:http://blog.51cto.com/8292516/2068383
时间: 2024-11-09 10:00:58