def run(): br = Browser(browser='chrome') br.goto("https://watir.com") # Check that "Titus" is somewhere in the page text assert "Watir" in br.text # Check "open source" is in the intro intro_text = br.div(class_name='intro').text assert "open source" in intro_text # Check that the page is correct via the URL br.link(text='Guides').click() assert 'watir.com/guides/' in br.url br.close()
"""Basic script showing how Nerodia works.""" from nerodia.browser import Browser br = Browser(browser='firefox') br.goto("https://watir.com") # Check that "Titus" is somewhere in the page text assert "Watir" in br.text # Check "open source" is in the intro intro_text = br.div(class_name='intro').text assert "open source" in intro_text # Check that the page is correct via the URL br.link(text='Guides').click() assert 'watir.com/guides/' in br.url br.close()
class Bot(Thread): def __init__(self, candidate, url, *args, **kwargs): super().__init__(*args, **kwargs) self.email = config('email') self.password = config('password') self.candidate = candidate self._running = False self.url = url self.browser = None self.open() def __exit__(self, exc_type, exc_val, exc_tb): self.close() def open(self): print('abrindo browser') self.browser = Browser('firefox') self.browser.goto(self.url) self.browser.wait() def close(self): print('fechando browser') self.browser.close() def auth(self): self.condidate_div.click() # IFRAME MALDITO! # with self.browser.windows[1] # self.browser. # login = self.browser.input(id='login') # login.wait_for_present() # login.send_keys(self.email) # # password = self.browser.input(id='password') # password.wait_for_present() # password.send_keys(self.password) # # entrar = self.browser.button(text='Entrar') # entrar.wait_for_present() # entrar.click() @property def condidate_div(self): return self.browser.div(text=self.candidate) @property def captcha_div(self): return self.browser.div(class_name=[ '_3xDixtS9TduMA-tXdgvxyM', '_2DsRxsoPgkhrq5exq-TSVO', '_2cZtCsRea_lK2Xi3dqwru' ]) def votar_novamente(self): button = self.browser.button(text='Votar Novamente') if button.present: print('vou votar novamente!') button.click() sleep(2) def votar(self): candidate = self.condidate_div if candidate.present: print('candidato presente!') candidate.click() sleep(2) while candidate.present: captcha_div = self.captcha_div captcha_div.wait_for_exists() print('Achei o captcha!') img = captcha_div.img() print('Vou clickar!') img.click() sleep(5) def run(self): # self.open_browser() # self.auth() self._running = True while self._running: try: self.votar() self.votar_novamente() except Exception as e: pass self.browser.close()
browser = Browser( 'chrome', headless=True ) # Set Headless to True so the physical GUI of Chrome doesn't have to be used ⚡️ browser.goto('https://www.premierleague.com/stats/top/players/goals?se=274' ) # Now use the browser to navigate to the EPL Stats Page time.sleep(5) # Allow data time to load into HTML goals = pd.read_html( browser.html )[0] # Use Pandas to fetch all the tables within the browser html, select the first table it finds ([0]) # When you've reached the end of the table, the Page Next button adds class 'inactive' to the page next element (div). Use browser tools to inspect the button on the last page to see for yourself. # As we know this, we can keep clicking the page next button and scraping the table until the button is inactive. In Python we can use while loop: while ((browser.div( class_name=["paginationBtn", "paginationNextContainer", "inactive"]) ).exists == False): browser.div( class_name=["paginationBtn", "paginationNextContainer"] ).fire_event( 'onClick' ) # fire onClick event on page next element. If it was a button element (not a div element), we could simply use .click() time.sleep(2) goals = goals.append( pd.read_html(browser.html)[0] ) # append the table from this page with the existing goals dataframe. print("Next Page") goals = goals[goals['Stat'] > 0] # Random Players at end of table wit 0 goals...
def main(): global browserTwitter, browserNewEgg, username, password, driver, options, rtxCardLink options.add_argument("--log-level=3") time.sleep(2) print("...") time.sleep(3) #start up text clear_console(5) print("Welcome to the RTX Bot Script!") clear_console(1) print("To begin, enter your username and password") print("to access your personal information") clear_console(5) #logs user in to retrieve personal information login() time.sleep(2) print("...") time.sleep(3) print("User successfully logged in!") #loads personal infrormation using password as key for decryption loadPersonalInformation() time.sleep(2) print("...") time.sleep(1) print("Personal Information Loaded!") time.sleep(2) print("...") time.sleep(3) print("Loading vpn...") ''' vpnStart() time.sleep(12) ''' print("Connected to VPN!") print("...") time.sleep(3) print("Loading browser to newegg...") time.sleep(2) driver = webdriver.Chrome(options=options) browserNewEgg = Browser(browser=driver) time.sleep(4) browserNewEgg.goto(rtxCardLink) wait(1) #clears browser cache browserNewEgg.cookies.clear() wait(9) #closes pop up if (browserNewEgg.link(id='popup-close').exists): browserNewEgg.link(id='popup-close').click() print("All set! Refreshing newegg until they restock") x = datetime.datetime.now() y = x + datetime.timedelta(seconds=120) #checks newegg until restock restocked = False count = 0 while restocked == False: if (count > 40): count = 0 time.sleep(1) print("Restarting browser with new IP...") #clears browser cache browserNewEgg.cookies.clear() time.sleep(1) #closes browser browserNewEgg.close() time.sleep(1) #disconnect from vpn vpnEnd() time.sleep(10) #reconnects to vpn vpnStart() time.sleep(12) driver = webdriver.Chrome(options=options) browserNewEgg = Browser(browser=driver) time.sleep(1) browserNewEgg.goto(rtxCardLink) time.sleep(12) #closes pop up if (browserNewEgg.link(id='popup-close').exists): browserNewEgg.link(id='popup-close').click() wait(2) else: pass browserNewEgg.refresh() wait(3) locator = {"class": "nav-col", "index": 1} condition = (browserNewEgg.div(class_name="product-buy").div().div( **locator).button()).exists x = datetime.datetime.now() condition = x > y if (condition): restocked = True else: pass count += 1 clear_console(100) print("Cards restocked!") time.sleep(1) #clicks add to cart browserNewEgg.div(class_name="product-buy").div().div( **locator).button().click() time.sleep(2) #declines warrenty if it is presented if (not (browserNewEgg.div(class_name="item-summary").exists)): locator = {"index": 0} browserNewEgg.div(class_name="modal-footer").button(**locator).click() time.sleep(2) #clicks view cart and checkout browserNewEgg.button(title="View Cart & Checkout").click() wait(5) #says no to masks if asked if (browserNewEgg.button(id="Masks_addtocart").exists): locator = {"index": 0} locator2 = {"index": 1} browserNewEgg.div(class_name="modal-footer").div(**locator2).button( **locator).click() time.sleep(2) #goes to secure checkout browserNewEgg.div(class_name="summary-actions").button().click()