Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mechanize
- import re
- # Make a Mech. browser
- br = mechanize.Browser()
- br.set_handle_robots(False)
- # Opens a Wikipedia site containing a list of Star Wars Characters and reads the entire site into a variable
- br.open('http://en.wikipedia.org/wiki/List_of_Star_Wars_characters')
- data = br.response().read()
- # Removes some of the HTML-code to ease the extraction of characters
- data = re.sub('<a.*?>', "", re.sub('</a>', "", re.sub('<span.*</span?>', "", data)))
- # Fetching all character names from website using regular expressions, removing some HTML-code and adding them to a list
- datalist = [i[4:len(i)-1] for i in re.findall('<dt>.*portrayed by?|<dt>.*voiced by?|<dt>.*?[<&]', data)]
- # Cleaning up empty strings and left-over HTML-code and HTML-formating
- for i in datalist:
- if ' ' in i:
- datalist[datalist.index(i)] = i[:i.index('&')]
- elif 'portrayed' in i:
- datalist[datalist.index(i)] = i[:i.index('portrayed')-3]
- elif 'voiced' in i:
- datalist[datalist.index(i)] = i[:i.index('voiced')-3]
- if '/' in i:
- datalist.remove(i)
- list = i.split('/')
- [datalist.append(j.strip()) for j in list]
- datalist = filter(None, datalist)
- # Creates a character list containing all the characters
- # by full name, firstname and lastname with first-letter upper case, all lower case and all uppercase
- characters = [str(i).strip() for i in datalist] + [str(i.lower()).strip() for i in datalist] + [str(i.upper()).strip() for i in datalist]
- for i in characters:
- plist = i.split()
- [characters.append(j.strip()) for j in plist if j not in characters]
- # Opens the stite containing the Star Wars guessing game
- br.open('http://172.16.0.50/game/guess.php')
- # For-loop to iterate through each character in the list
- for i in characters:
- # Selects the form
- br.select_form(nr=0)
- # Sett Group 5 as username
- br.form['username'] = '05'
- # Set character
- br.form['character'] = i
- # Submits the form
- br.submit()
- # Prints the character tried to give the user some visual feedback
- print "Submited: " + "05 | " + i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement