def start_and_login(): while True: opts = chromeOpts() opts.add_argument(f"user-agent={ua.random}") prefs = { 'profile.managed_default_content_settings.images': 2 } # Disallow images from loading opts.add_experimental_option("prefs", prefs) driver = helium.start_chrome( "https://www.udemy.com/random_page_that_does_not_exist/", headless=False, options=opts) driver.add_cookie({ 'name': 'client_id', 'value': client_id, 'domain': udemy_domain }) driver.add_cookie({ 'name': 'access_token', 'value': access_token, 'domain': udemy_domain }) helium.go_to("https://www.udemy.com/?persist_locale=&locale=en_US") if 'upgrade-your-browser' in driver.current_url: driver.quit() else: break try: helium.wait_until(helium.Button('Log in').exists, timeout_secs=3.5) helium.kill_browser() raise InvalidCookiesException() except TimeoutException: return driver
def get_interactive_page_source(url): """Obtém código-fonte completo da página.""" # inicia o chrome para renderizar o código-fonte try: start_chrome(url, headless=True) except Exception: print( "Erro: você precisa instalar o Google Chrome e o ChromeDriver par" "a executar esse raspador.") sys.exit(1) driver = get_driver() # clica em todos os botões "Veja mais!" para liberar os dados dos resumos print( f"Raspando a página \"{driver.title}\". Isso pode demorar alguns segundos..." ) buttons = find_all(S("//span[@onClick]")) for _ in tqdm(range(len(buttons))): click("Veja mais!") print('Fim da raspagem da página.') # obtém objeto soup a partir do código-fonte renderizado pelo helium soup = BeautifulSoup(driver.page_source, 'html.parser') # fecha o chrome kill_browser() return soup
def test_invalid_credentials(self): driver = helium.start_chrome('https://goantifraud.com/manager', headless=True) helium.write(TEST_DATA['invalid_credentials']['log'], into='login') helium.write(TEST_DATA['invalid_credentials']['pass'], into='password') helium.press(helium.ENTER) check = helium.Text('Login or password is incorrect').value helium.kill_browser() self.assertEqual(check, 'Login or password is incorrect')
def test_recover_pass_with_invalid_user(self): driver = helium.start_chrome('https://goantifraud.com/manager', headless=True) helium.click('Forgot your password?') helium.write(TEST_DATA['invalid_credentials']['log'], into='login') helium.click('SEND') time.sleep(0.5) validation_msg_list = helium.find_all(helium.S(".error.error_show")) helium.kill_browser() self.assertEqual(len(validation_msg_list), 2)
def submit_request(song, artist, url='www.harmonixmusic.com/games/rock-band/request'): "Uses helium framework to open chrome, open a website, and submit a song" logging.info("Logging into %s", url) start_chrome(url, headless=True) write(song, into='Song Title') write(artist, into='Artist') logging.info("Submitting request for '%s' by '%s'", song, artist) click('Submit') kill_browser()
def run_url_catcher(): try: wait_until(fetch_download_url, timeout_secs=15) except TimeoutException as e: print("Failed!") print(e) else: return URL finally: kill_browser() if URL is None: sys.exit(1)
def getDemons(name): list1 = [] list0 = [] start_chrome('https://pointercrate.com/demonlist/') press(END) press(PAGE_UP) click('Open the stats viewer!') write(name, into='Enter to search...') click(name) time.sleep(1) main_is_empty = 1 extended_is_empty = 1 mainverifs_is_empty = 1 extendedverifs_is_empty = 1 for x in range(75): counter = x + 1 if main_is_empty: mainlist = find_all(S('//*[@id="beaten"]/b[%d]/a' % (counter))) if extended_is_empty: extendedlist = find_all( S('//*[@id="beaten"]/span[%d]/a' % (counter))) if mainverifs_is_empty: verifications_main = find_all( S('//*[@id="verified"]/b[%d]/a' % (counter))) if extendedverifs_is_empty: verifications_extended = find_all( S('//*[@id="verified"]/span[%d]/a' % (counter))) if mainlist == []: main_is_empty = 0 if extendedlist == []: extended_is_empty = 0 if verifications_main == []: mainverifs_is_empty = 0 if verifications_extended == []: extendedverifs_is_empty = 0 list0.append(mainlist) list0.append(extendedlist) list0.append(verifications_main) list0.append(verifications_extended) list0 = [element for element in list0 if element != []] for demon in list0: demon = str(demon) start = [m.start() for m in re.finditer(">", demon)][0] end = [m.start() for m in re.finditer("<", demon)][1] demon = demon[(start + 1):end] list1.append(demon) kill_browser() return list1
def exit(self): helium.kill_browser()
import helium import hashlib driver = helium.start_chrome("https://temp-mail.org/en/", headless=True) helium.wait_until( lambda: "@" in helium.TextField("Your Temporary email address").value) email = helium.TextField("Your Temporary email address").value password = hashlib.sha1(email.encode()).hexdigest() print(email, password) helium.kill_browser() driver = helium.start_chrome("https://www.kartable.fr/inscription") helium.click("élève") helium.click("1ère") helium.click("s'inscrire avec un e-mail") helium.write("Cld", into="prénom") helium.write("Lokidod", into="nom") helium.write(email, into="adresse e-mail") helium.write(password, into="mot de passe") helium.click("terminer") helium.wait_until(helium.Text("plus tard").exists) helium.click("plus tard") #helium.kill_browser()
def using_firefox(): start_firefox() try: yield finally: kill_browser()
def tearDownModule(): global _TEST_BROWSER if _TEST_BROWSER is not None: kill_browser() _TEST_BROWSER = None
def tearDownClass(cls): if cls.started_browser: kill_browser()
def stop_and_save(fileName, listPosts): print("Save crawled data...") with open(fileName, "w", encoding="utf-8") as file: json.dump(listPosts, file, ensure_ascii=False, indent=4) kill_browser()
import helium # 比较适合新手的自动化库 from time import sleep home_url = 'https://mail.163.com/' # 网站主地址 user_name = 'luobomc' # 登陆用户名 password = '******' # 密码 driver = helium.start_chrome(home_url) # 打开浏览器 并且打开home_url地址页面 sleep(5) # 睡眠5s等待页面加载 helium.write(user_name, helium.TextField('邮箱帐号或手机号码')) # 锁定'邮箱账号或手机号码'并且锁定 然后传入用户名 sleep(2) # 睡眠2秒 helium.write(password, helium.TextField('输入密码')) # 锁定密码输入框并且输入 helium.press(helium.ENTER) # 模拟按回车 登录 sleep(5) # 睡眠5秒等待页面刷新 helium.click(helium.Text('收 信')) # 点击收信按钮 查看邮件 helium.kill_browser() # 关闭浏览器
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: kill_browser() dispatcher.utter_message("已关闭") return []
/ args.slide_path_or_directory_name ) slides = list(slide_directory.glob("*.html")) assert len(slides) == 1, str(slides) slide_html_path = slides[0] else: # Case: slide path slide_html_path = Path(args.slide_path_or_directory_name).resolve() slide_page_url = slide_html_path.as_uri() # タイトルが長い場合は2枚めを使う運用をしている if args.is_long_title: slide_page_url += "#/1" if not args.output_path: args.output_path = ( project_root / "docs" / "_images" / "ogps" / f"{slide_html_path.stem}.png" ) options = FirefoxOptions() options.add_argument("--width=800") options.add_argument("--height=485") # ブラウザウィンドウ上部が85px分ある start_firefox(options=options, headless=True) go_to(slide_page_url) # TODO: #/1 のようにページの指定を追加可能に get_driver().save_screenshot(str(args.output_path)) kill_browser()