Advertisement
konchin_shih

poop

Feb 18th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. from urllib.request import urlopen, Request
  2. from urllib.error import HTTPError, URLError
  3. from bs4 import BeautifulSoup
  4. from os import mkdir
  5.  
  6.  
  7. def buildpath(path):
  8.     curpath = './'
  9.     while path.find('/') != -1:
  10.         curpath += path[:path.find('/') + 1]
  11.         path = path[path.find('/') + 1:]
  12.         try:
  13.             mkdir(curpath)
  14.         finally:
  15.             continue
  16.  
  17.  
  18. AID = "1592"
  19. CID = ["61675", "62882", "62883", "62884", "65271", "66589", "67414",
  20.        "68813", "68814", "75076", "77798", "85378", "89626", "105269", "108790"]
  21. urlBase = "http://picture.wenku8.com/pictures/1/" + AID + "/";
  22.  
  23.  
  24. def getImage(cid, pid):
  25.     url = urlBase + cid + '/' + pid + '.jpg'
  26.     try:
  27.         req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
  28.         data = urlopen(req)
  29.     except HTTPError as e:
  30.         return False
  31.     except URLError as e:
  32.         return False
  33.     else:
  34.         print(url, " ... success")
  35.         url = url[26:]
  36.         buildpath(url)
  37.         file = open(url, 'wb')
  38.         file.write(data.read())
  39.         file.close()
  40.         return True
  41.  
  42.  
  43. cur = 1
  44. for cid in CID:
  45.     while getImage(cid, str(cur)) == False:
  46.         cur += 10
  47.  
  48.     forward = cur
  49.     while getImage(cid, str(forward)) == True:
  50.         forward -= 1
  51.     while getImage(cid, str(cur)) == True:
  52.         cur += 1
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement