Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib.request import urlopen, Request
- from urllib.error import HTTPError, URLError
- from bs4 import BeautifulSoup
- from os import mkdir
- def buildpath(path):
- curpath = './'
- while path.find('/') != -1:
- curpath += path[:path.find('/') + 1]
- path = path[path.find('/') + 1:]
- try:
- mkdir(curpath)
- finally:
- continue
- AID = "1592"
- CID = ["61675", "62882", "62883", "62884", "65271", "66589", "67414",
- "68813", "68814", "75076", "77798", "85378", "89626", "105269", "108790"]
- urlBase = "http://picture.wenku8.com/pictures/1/" + AID + "/";
- def getImage(cid, pid):
- url = urlBase + cid + '/' + pid + '.jpg'
- try:
- req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
- data = urlopen(req)
- except HTTPError as e:
- return False
- except URLError as e:
- return False
- else:
- print(url, " ... success")
- url = url[26:]
- buildpath(url)
- file = open(url, 'wb')
- file.write(data.read())
- file.close()
- return True
- cur = 1
- for cid in CID:
- while getImage(cid, str(cur)) == False:
- cur += 10
- forward = cur
- while getImage(cid, str(forward)) == True:
- forward -= 1
- while getImage(cid, str(cur)) == True:
- cur += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement