爬取wanimal图片
from urllib.request import urlopen, urlretrieve
from bs4 import BeautifulSoup
from urllib.error import URLError, HTTPError
import requests
class Wanimal:
def __init__(self, page):
self.page = page
self.imgs = []
def getPage(self, page):
try:
html = urlopen("http://wanimal1983.org/page/"+str(page))
bsobj = BeautifulSoup(html, "html.parser")
return bsobj
except (URLError, HTTPError) as e:
print (e)
return None
def getImages(self, page):
print ("正在加载第%d页" % page)
bsobj = self.getPage(page)
imgTags = bsobj.findAll("div", {"class": "photo-sets"})
self.imgs = []
for imgTag in imgTags:
for img in imgTag.findAll("img"):
self.imgs.append(img)
def