Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
- import time
- firefoxProfile = FirefoxProfile()
- ## Disable images
- firefoxProfile.set_preference('permissions.default.image', 2)
- ## Disable Flash
- firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
- 'false')
- driver_freerice = webdriver.Firefox(firefoxProfile)
- driver_freerice.get("http://freerice.com/#/english-vocabulary")
- driver_thesaurus = webdriver.Firefox()
- driver_thesaurus.set_page_load_timeout(3.5)
- grains = 0
- while True:
- time.sleep(1.5)
- word = driver_freerice.find_elements_by_xpath("//*[contains(text(), 'means:')]")[1].text.split()[0]
- answers = []
- for answer in driver_freerice.find_elements_by_class_name("answer-item"):
- answers.append((answer.text, answer))
- print "Current grains: "+str(grains)
- print "Current word: "+word
- print "Candidates:"
- for a in answers: print " "+a[0]
- try: driver_thesaurus.get("http://www.thesaurus.com/browse/"+word+"?s=t")
- except Exception as e: pass
- try:
- try: e = [driver_thesaurus.find_element_by_xpath('.//strong[@class = "ttl"]')]
- except: e = []
- for syn in driver_thesaurus.find_elements_by_xpath('.//span[@class = "text"]')+e:
- for ans in answers:
- if syn.text == ans[0]:
- print "Gotcha! Found synonym: "+syn.text+"\n"
- ans[1].click()
- grains += 10
- raise Exception("woo")
- print "Could not find synonym :(\n"
- answers[0][1].click()
- except Exception as e:
- if str(e) == "woo": continue
- else:
- print str(e)
- driver_freerice.get("http://freerice.com/#/english-vocabulary")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement