how to click on a button in python


SUBMITTED BY: Guest

DATE: Feb. 10, 2014, 8:34 p.m.

FORMAT: Python

SIZE: 3.6 kB

HITS: 46004

  1. #!/usr/bin/python
  2. # FILENAME: test.py
  3. import mechanize
  4. import os, time
  5. from random import choice, randrange
  6. prox_list = []
  7. #list of common UAS to apply to each connection attempt to impersonate browsers
  8. user_agent_strings = [ 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36',
  9. 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1',
  10. 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
  11. 'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52',
  12. 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:23.0) Gecko/20131011 Firefox/23.0',
  13. 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7',
  14. 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; Tablet PC 2.0; InfoPath.3; .NET4.0C; .NET4.0E)',
  15. 'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0',
  16. 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; chromeframe/11.0.696.57)',
  17. 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; InfoPath.1; SV1; .NET CLR 3.8.36217; WOW64; en-US)',
  18. 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)'
  19. ]
  20. def load_proxy_list(target):
  21. #loads and parses the proxy list
  22. file = open(target, 'r')
  23. count = 0
  24. for line in file:
  25. prox_list.append(line)
  26. count += 1
  27. print "Loaded " + str(count) + " proxies!"
  28. load_proxy_list('proxies.txt')
  29. #for i in range(1,(len(prox_list) - 1)):
  30. # depreceated for overloading
  31. for i in range(1,30):
  32. br = mechanize.Browser()
  33. #pick a random UAS to add some extra cover to the bot
  34. br.addheaders = [('User-agent', choice(user_agent_strings))]
  35. print "----------------------------------------------------"
  36. #This is bad internet ethics
  37. br.set_handle_robots(False)
  38. #choose a proxy
  39. proxy = choice(prox_list)
  40. br.set_proxies({"http": proxy})
  41. br.set_debug_http(True)
  42. try:
  43. print "Trying connection with: " + str(proxy)
  44. #currently using: BTC CoinURL - Grooveshark Broadcast
  45. br.open("http://cur.lv/4czwj")
  46. print "Opened successfully!"
  47. #act like a nice little drone and view the ads
  48. sleep_time_on_link = randrange(17.0,34.0)
  49. time.sleep(sleep_time_on_link)
  50. except mechanize.HTTPError, e:
  51. print "Oops Request threw " + str(e.code)
  52. except mechanize.URLError, e:
  53. print "Oops! Request was refused, blacklisting proxy!" + str(e)
  54. prox_list.remove(proxy)
  55. del br #close browser entirely
  56. #wait between 5-30 seconds like a good little human
  57. sleep_time = randrange(5.0, 30.0)
  58. print "Waiting for %.1f seconds like a good bot." % (sleep_time)
  59. time.sleep(sleep_time)

comments powered by Disqus