This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
python-aternos/python_aternos/atselenium.py

51 lines
1.4 KiB
Python
Raw Normal View History

2023-08-08 10:57:41 +04:00
from selenium.webdriver import Remote
from selenium.webdriver.support.wait import WebDriverWait
BASE_URL = 'https://aternos.org'
RM_SCRIPTS = '''
const rmScripts = () => {
const lst = document.querySelectorAll("script")
for (let js of lst) {
if (
js.src.includes('googletagmanager.com') ||
js.src.includes('cloudflareinsights.com') ||
js.innerText.includes('LANGUAGE_VARIABLES')
) {
js.remove()
}
2023-08-08 10:57:41 +04:00
}
}
addEventListener('DOMContentLoaded', rmScripts)
rmScripts()
2023-08-08 10:57:41 +04:00
'''
class SeleniumHelper:
def __init__(self, driver: Remote) -> None:
self.driver = driver
self.wait = WebDriverWait(driver, 8.0)
self.find_element = self.driver.find_element
self.find_elements = self.driver.find_elements
2023-08-08 10:57:41 +04:00
def load_page(self, path: str) -> None:
self.driver.get(f'{BASE_URL}{path}')
self.driver.execute_script(RM_SCRIPTS)
def exec_js(self, script: str) -> None:
self.driver.execute_script(script)
def get_cookie(self, name: str) -> str:
cookie = self.driver.get_cookie(name)
if cookie is None:
return ''
return cookie.get('value') or ''
def set_cookie(self, name: str, value: str) -> None:
self.driver.add_cookie({
'name': name,
'value': value,
})