Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. import mechanize
  2. import re
  3.  
  4. # Make a Mech. browser
  5. br = mechanize.Browser()
  6. br.set_handle_robots(False)
  7.  
  8. # Opens a Wikipedia site containing a list of Star Wars Characters and reads the entire site into a variable
  9. br.open('http://en.wikipedia.org/wiki/List_of_Star_Wars_characters')
  10. data = br.response().read()
  11.  
  12. # Removes some of the HTML-code to ease the extraction of characters
  13. data = re.sub('<a.*?>', "", re.sub('</a>', "", re.sub('<span.*</span?>', "", data)))
  14.  
  15. # Fetching all character names from website using regular expressions, removing some HTML-code and adding them to a list
  16. datalist = [i[4:len(i)-1] for i in re.findall('<dt>.*portrayed by?|<dt>.*voiced by?|<dt>.*?[<&]', data)]
  17.  
  18. # Cleaning up empty strings and left-over HTML-code and HTML-formating
  19. for i in datalist:
  20.     if '&#160' in i:
  21.         datalist[datalist.index(i)] = i[:i.index('&')]
  22.     elif 'portrayed' in i:
  23.         datalist[datalist.index(i)] = i[:i.index('portrayed')-3]
  24.     elif 'voiced' in i:
  25.         datalist[datalist.index(i)] = i[:i.index('voiced')-3]
  26.     if '/' in i:
  27.         datalist.remove(i)
  28.         list = i.split('/')
  29.         [datalist.append(j.strip()) for j in list]
  30. datalist = filter(None, datalist)
  31.  
  32. # Creates a character list containing all the characters
  33. # by full name, firstname and lastname with first-letter upper case, all lower case and all uppercase
  34. characters = [str(i).strip() for i in datalist] + [str(i.lower()).strip() for i in datalist] + [str(i.upper()).strip() for i in datalist]
  35. for i in characters:
  36.     plist = i.split()
  37.     [characters.append(j.strip()) for j in plist if j not in characters]
  38.  
  39. # Opens the stite containing the Star Wars guessing game
  40. br.open('http://172.16.0.50/game/guess.php')
  41.  
  42. # For-loop to iterate through each character in the list
  43. for i in characters:
  44.     # Selects the form
  45.     br.select_form(nr=0)
  46.  
  47.     # Sett Group 5 as username
  48.     br.form['username'] = '05'
  49.  
  50.     # Set character
  51.     br.form['character'] = i
  52.  
  53.     # Submits the form
  54.     br.submit()
  55.  
  56.     # Prints the character tried to give the user some visual feedback
  57.     print "Submited: " + "05 | " + i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement