def test_raises_correct_exception_when_trying_to_interact_with_a_closed_browser( self, bkwargs, page): from nerodia.browser import Browser from nerodia.exception import Error with pytest.raises(Error) as e: b = Browser(**bkwargs) b.goto(page.url('definition_lists.html')) b.close() b.dl(id='experience-list').id assert e.value.args[0] == 'browser was closed'
def basicSearch(): # Retirado do Site do Nerodia, para teste inicial # browser = Browser(browser='chrome') browser.goto('google.com') search_input = browser.text_field(title='Pesquisar') search_input.value = 'nerodia' browser.button(value='Pesquisa Google').click() browser.close()
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()
def main(site): "Get all redirect links to a series (still have to extract manually fromAndTo is an good option for this)" base = 'https://s.to' if base in site: site = site.replace(base, "") if not site[-1] == "/": site = site + "/" #print(base) #print(site) browser = Browser(browser='firefox') browser.goto(base + site) html = browser.html matches = re.findall( '<a (?:class="active" )?href="(' + site + r'staffel-\d+)" title="Staffel \d+">\d+</a>', html) #print(matches) episodeRegex = re.compile( r'<a href="(' + site + r'staffel-\d+/episode-\d+)" data-episode-id="\d*" title="Staffel \d+ Episode \d+" data-season-id="\d+">\d+</a>' ) allepisodes = list() for m in matches: browser.goto(base + m) html = browser.html episodes = episodeRegex.findall(html) allepisodes.extend(episodes) #print(allepisodes) VivoRegex = re.compile( r'<aclass="watchEpisode"itemprop="url"href="(/redirect/\d*)"target="_blank">\n<iclass="iconVivo"title="HosterVivo"></i>\n<h4>Vivo</h4>\n<divclass="hosterSiteVideoButton">Videoöffnen</div>' ) vivolinks = list() for e in allepisodes: browser.goto(base + e) html = browser.html html = html.replace(" ", "") vivolink = VivoRegex.findall(html) vivolinks.append(vivolink[0]) #print(vivolinks) for vl in vivolinks: print(base + vl) browser.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()
for t in list(tabs): if not t.goto_next_url(random.choice(range(1, 20))): tabs.remove(t) urls_visited = urls_visited + len(t.urls_visited) if urls_visited >= tabs_required_randomise_last + tabs_required_randomise_period: tabs_required = int(tabs_required * random.choice((0.25, 0.5, 2, 4))) tabs_required = max(1, min(tabs_required, params.tabs_max)) tabs_required_randomise_last = urls_visited if workload_pause_period > 0 and urls_visited >= workload_pause_last + workload_pause_period: sleep(240) workload_pause_last = urls_visited print('OK -- done', file=sys.stderr) browser.close() ''' with browser.window(handle=browser.wd.window_handles[0]) as w: browser.goto('google.com') w.close() browser.execute_script('window.open()') with browser.window(handle=browser.wd.window_handles[-1]) as w: browser.goto('google.com') w.close() for wh in browser.wd.window_handles: w = browser.window(handle=wh) with w: browser.goto('google.com') # also #w.use()
def test_works_even_if_browser_is_closed(self, browser, bkwargs): b = Browser(**bkwargs) b.close() repr(b)
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... goals = goals.dropna( axis=1, how='all' ) # Random Unamed Column (all NaN elements, so clear columns where 'all' values are NaN) goals.to_csv(r'data/epl_goals_19_20.csv', index=False) # Save dataframe to new csv file browser.close() # Close Browser
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()
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()