requestFile(img, sock) sock.close() serverName = "localhost" serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName, serverPort)) f = open("index.html", "a") data = requestFile("index.html", clientSocket) # request index f.write(data) f.close() clientSocket.close() # close sockets IParser = parser.parselinks() # parse index path = os.getcwd() IParser.feed(urllib.urlopen(path + "/index.html").read().decode("utf-8")) imgarr = IParser.getresult() # get all img files newImgarr = [] for item in imgarr: # preProcess img url item = item[1:] newImgarr.append(item) pool = multiprocessing.Pool(processes=5) smallsize = len(newImgarr) / 5 A = newImgarr[0:smallsize] B = newImgarr[smallsize : smallsize * 2] C = newImgarr[smallsize * 2 : smallsize * 3] D = newImgarr[smallsize * 3 : smallsize * 4] E = newImgarr[smallsize * 4 :]
filename= 'index.html' finenamed=filename.encode() print(finenamed) clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) #sentence = input('Input lowercase sentence:') clientSocket.send(filename) f = open('index.html','a') print ('writing') data = recv_timeout(clientSocket,1) f.write(data) #fileReceive = clientSocket.recv(1024) #print ('From Server:', modifiedSentence) f.close() IParser = parser.parselinks() IParser.feed(urllib.urlopen('file:///Users/jianshenhe/desktop/network/index.html').read().decode('utf-8')) imgarr = IParser.getresult() print(imgarr) newImgarr = [] for item in imgarr: item = item[1:] newImgarr.append(item) #for img in newImgarr: print('req img') requestFile(newImgarr[1],clientSocket) clientSocket.close()