Oct-07-2017, 05:26 PM
Hello all,
First time here. So I've pieced together some code and can't quite figure out how to get it to work. It's not throwing any errors, but it isn't printing any results either. Basically the code reaches out, logs into a website, grabs a wordsearch grid, and is supposed to perform a word search for words 6 characters or longer. Any pointers?
First time here. So I've pieced together some code and can't quite figure out how to get it to work. It's not throwing any errors, but it isn't printing any results either. Basically the code reaches out, logs into a website, grabs a wordsearch grid, and is supposed to perform a word search for words 6 characters or longer. Any pointers?
#begin module imports import re, os, sys, time, getpass try: import requests except: exit('[-] Importing Requests module failed') #Begin with login to WordSearchWeb class WordSearchWeb: loginUrl = 'http://www.WordSearchWeb.net/login' challUrl = 'http://www.WordSearchWeb.net/index.php' gridsUrl = 'http://www.WordSearchWeb.net/lettergrid/generate.php' def __init__(self, username, password, s) : self.login(username, password, s) self.sidebar(s) self.gridSRC = self.getgrid(s) self.searchgrid(self.gridSRC) print ' '.join(sorted(set(word for (word, path) in self.solve()))) def login(self, username, password, s): r = s.get(self.loginUrl) r = s.post(self.loginUrl, data = {'username' : username, 'password' : password, 'login' : 'Login'}) if 'Welcome back to WordSearchWeb' in r.text: print('[+] Login Successful') c = r.request.headers['Cookie'] self.Cookie = c return s def sidebar(self, s): print('[+] Closing Side bar for faster page load') r = s.get('http://www.WordSearchWeb.net/index.php?mo=WordSearchWeb&me=Sidebar2&rightpanel=0') def getgrid(self, s): print('[+] Getting source code of generate.php') r = s.get(self.gridsUrl) gridSRC = r.content gridSRC = gridSRC.replace('<pre>','') gridSRC = gridSRC.replace('</pre>','') print gridSRC gridSRC = gridSRC.replace('\n',' ') gridSRC = str(gridSRC[1:len(gridSRC)-1]) return gridSRC def searchgrid(self, grid): gridSRC=self.getgrid(s) self.grid = grid grid = gridSRC.split() print grid nrows, ncols = len(grid), len(grid[0]) alphabet = ''.join(set(''.join(grid))) bogglable = re.compile('[' + alphabet + ']{6,}$', re.I).match self.words = set(word.rstrip('\n') for word in open('words') if bogglable(word)) prefixes = set(word[:i] for word in self.words for i in range(2, len(word)+1)) def solve(self): grid = self.grid for y, row in enumerate(grid): for x, letter in enumerate(row): for result in self.extending(letter, ((x, y),)): yield result def extending(self, prefix, path): if prefix in self.words: yield (prefix, path) for (nx, ny) in neighbors(path[-1]): if (nx, ny) not in path: prefix1 = prefix + grid[ny][nx] if prefix1 in prefixes: for result in extending(prefix1, path + ((nx, ny),)): yield result def neighbors((x, y)): for nx in range(max(0, x-1), min(x+2, ncols)): for ny in range(max(0, y-1), min(y+2, nrows)): yield (nx, ny) u = 'myuser' p = 'mypass' s = requests.Session() WordSearchWeb(u,p,s)


