import urllib.request
import socket
import re
import sys
import os
import math
targetDir = r"D:\images"
def destFile(path):
if not os.path.isdir(targetDir):
os.mkdir(targetDir)
pos = path.rindex('/')
t = os.path.join(targetDir, path[pos + 1:])
return t
if __name__ == "__main__":
hostname = "http://vscom.mayuko.cn/"
req = urllib.request.Request(hostname)
webpage = urllib.request.urlopen(req)
contentBytes = webpage.read()
for link, t in set(re.findall(r'(http://[^\s]*?(jpg))', str(contentBytes))):
print("Cache the images of " + link)
urllib.request.urlretrieve(link, destFile(link))
print("Cache done")