Urllib+BeautifulSoup(抓取图片)

更多爬虫实例请见 https://blog.csdn.net/weixin_39777626/article/details/81564819

from urllib.request import urlopen,urlretrieve
from bs4 import BeautifulSoup

def getUrl(url):
    try:
        douban=urlopen(url)
        bs4=BeautifulSoup(douban,'lxml')
        pictures=bs4.find_all('li',class_='subject-item')
        number=1
        for a in pictures:
            picture=a.find('a','nbg').find('img').get('src')
            name=a.find('h2').find('a').get('title')+'.jpg'
            urlretrieve(picture,name)
            number=number+1
    except:
        return '...'
j=0
for i in range(1,94):
    getUrl('https://book.douban.com/tag/%E7%AE%97%E6%B3%95?'+'start=%d&type=T'%j)
    j=j+20

更多爬虫实例请见 https://blog.csdn.net/weixin_39777626/article/details/81564819

你可能感兴趣的:(爬虫)