コード例 #1
0
 def create_loading_strategy_options(self, loading_strategy: str) -> Options:
     options = Options()
     if loading_strategy == "none":
         options.page_load_strategy = "none"
     elif loading_strategy == "eager":
         options.page_load_strategy = "eager"
     else:
         options.page_load_strategy = "normal"
     return options
コード例 #2
0
    def __init__(self):

        self.pessoas = ['Jhonnatan']
        self.mensagem = 'Olá mundo, sou um botzinho que está aprendendo a digitar sozinho'
        options = Options()
        options.page_load_strategy = 'eager'  # Carrega o essencial da pagina para melhorar a performance do algoritmo.
        self.driver = Firefox(executable_path=r'./geckodriver.exe')
コード例 #3
0
def download_links(user_file, link_file):
    load_dotenv(".env")
    course_id = os.getenv("COURSE_ID", None)
    username = os.getenv("BB_USERNAME", None)
    password = os.getenv("BB_PASSWORD", None)

    if course_id is None:
        course_id = input("Course ID: ")
    if username is None:
        username = input("Username: "******"Password: "******"download"
    os.mkdir(temp_working_dir)
    os.mkdir(temp_download_dir)

    options = Options()
    options.page_load_strategy = "none"

    profile = BbAPI.get_firefox_profile(temp_download_dir)
    driver = webdriver.Firefox(firefox_profile=profile, options=options)
    driver.command_executor.set_timeout(20)
    driver.implicitly_wait(5)
    driver.set_page_load_timeout(5)
    driver.set_script_timeout(5)
    api = BbAPI(course_id, driver)

    api.login(username, password)

    df = pd.read_csv(user_file)
    df["full_name"] = df["firstName"] + " " + df["lastName"]

    with open(link_file, "r") as f:
        entries = json.load(f)

        for entry in entries:
            email_handle = df[df["full_name"] == entry["name"]]["emailHandle"].values[0]
            print("Processing", entry["name"], email_handle)

            entry_dir = Path(os.path.join(temp_working_dir, email_handle))

            if not entry_dir.is_dir():
                os.mkdir(entry_dir)

            if len(entry["url"]) == 0:
                continue

            api.get_file(entry["url"])

            print("Moving files")
            files = list(temp_download_dir.glob("*"))
            if len(files) >= 1:
                for f in files:
                    shutil.move(f, entry_dir)

            sleep(1.3)

    print("Working directory was {temp_working_dir}")
コード例 #4
0
ファイル: main.py プロジェクト: videobitva/GTFObonch
    def __init__(self,
                 bonch_username,
                 bonch_password,
                 google_username,
                 google_password,
                 driver,
                 firefox=False,
                 chrome=False,
                 strategy="normal"):
        self.bonch_username = bonch_username
        self.bonch_password = bonch_password
        self.google_username = google_username,
        self.google_password = google_password,
        self.timetable = []

        self.lk_ready = False
        self.google_ready = False

        self.browser = None

        self.lk_handle = None
        self.google_handle = None

        if firefox:
            options = FirefoxOptions()
            options.page_load_strategy = strategy
            options.add_argument("--incognito")
            # options.add_argument("--use-fake-device-for-media-stream")
            # options.add_argument("--use-fake-ui-for-media-stream")
            self.browser = webdriver.Firefox(executable_path=driver,
                                             options=options)
        elif chrome:
            options = ChromeOptions()
            options.page_load_strategy = strategy
            options.add_argument("--incognito")
            # options.add_argument("--use-fake-device-for-media-stream")
            # options.add_argument("--use-fake-ui-for-media-stream")
            self.browser = webdriver.Chrome(executable_path=driver,
                                            options=options)
        else:
            raise ValueError("No browser type specified!")
    def __options(self):
        """
		Configuring options of the Bot
		"""
        options = Options()
        options.add_argument("Cache-Control=no-cache")
        options.add_argument("--no-sandbox")
        options.add_argument("--dns-prefetch-disable")
        options.add_argument("--disable-dev-shm-usage")
        options.add_argument("--disable-web-security")
        options.add_argument("--ignore-certificate-errors")
        options.page_load_strategy = 'none'
        options.add_argument("--ignore-certificate-errors-spki-list")
        options.add_argument("--ignore-ssl-errors")
        return options
コード例 #6
0
def download_tiktok_video(url: str) -> str:
    '''
    Download a TikTok video

    Parameters:
            url (str): any url that leads to a tik tok

    Returns:
            path (str): Absolute path to the downloaded file
    '''
    options = Options()
    options.add_argument('--headless')
    options.page_load_strategy = 'eager'

    profile = FirefoxProfile()
    profile.set_preference('browser.download.folderList', 2)
    profile.set_preference('browser.download.dir', cwd)
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
                           'video/mp4, application/octet-stream, mp4')
    profile.set_preference('browser.download.manager.showWhenStarting', False)
    profile.set_preference('browser.download.useDownloadDir', True)
    profile.set_preference('browser.download.viewableInternally.enabledTypes',
                           '')
    profile.set_preference('media.play-stand-alone', False)
    profile.set_preference('webdriver.load.strategy', 'fast')
    profile.set_preference('browser.tabs.remote.autostart.2', False)

    driver = webdriver.Firefox(profile, options=options)

    driver.get(url)
    elem = driver.find_element(By.TAG_NAME, 'video')
    src = elem.get_attribute('src')
    script = f'''
        var link = document.createElement('a');
        link.setAttribute('download', 'download');
        link.setAttribute('href', '{src}');
        link.click();
        document.title = "dl start";
        '''
    driver.execute_script(script)
    WebDriverWait(driver, 60).until(title_is('dl start'))
    while (os.path.getsize('mp4') == 0):
        pass
    new_name = 'v.mp4'
    os.rename('mp4', new_name)
    driver.quit()
    return os.path.abspath(new_name)
コード例 #7
0
profile.set_preference("browser.urlbar.showSearch",
                       False)  # Disable search bar.
profile.set_preference("extensions.checkCompatibility",
                       False)  # Addon update disabled
profile.set_preference("extensions.checkUpdateSecurity", False)
profile.set_preference("extensions.update.autoUpdateEnabled", False)
profile.set_preference("extensions.update.enabled", False)
profile.set_preference("general.startup.browser", False)
profile.set_preference("plugin.default_plugin_disabled", False)
profile.set_preference("permissions.default.image",
                       2)  # Image load disabled again

driver = webdriver.Firefox(options=options,
                           executable_path='D:\\chromedriver\geckodriver.exe')
driver.implicitly_wait(10)
options.page_load_strategy = 'eager'
#driver = webdriver.Firefox(executable_path='D:\\chromedriver\geckodriver.exe')

driver.get(
    "https://stm.semfaz.saoluis.ma.gov.br/sistematributario/jsp/login/login.jsf"
)

username = driver.find_element_by_id("frmLogin:txtLogin")
username.clear()
username.send_keys("{login}")
print("username colocado")
password = driver.find_element_by_name("frmLogin:j_id8")
password.clear()
password.send_keys("{senha}")
print("password colocado")
コード例 #8
0
def get_driver() -> webdriver.Firefox:
    o = Options()

    o.page_load_strategy = 'eager'

    return webdriver.Firefox(options=o)
コード例 #9
0
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

from PIL import Image
from bs4 import BeautifulSoup
import requests

url = 'http://www.portalredevw.com.br/'

login = '******'
password = '******'

options = Options()
options.page_load_strategy = 'normal'

browser = webdriver.Firefox(options=options)
browser.get(url)

frame_1 = browser.find_element_by_xpath('/html/frameset/frame[1]')
browser.switch_to.frame(frame_1)

frame_2 = browser.find_element_by_xpath('//*[@id="divframe"]')
browser.switch_to.frame(frame_2)

frame_3 = browser.find_element_by_xpath('//*[@id="main"]')
browser.switch_to.frame(frame_3)

frame_4 = browser.find_element_by_xpath('//*[@id="mainApp"]')
browser.switch_to.frame(frame_4)
コード例 #10
0
ファイル: test.py プロジェクト: sisiair/pystest
def main():
    global proxy_client, proxy_server
    LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
    log_filename = 'logs/test_' + time.strftime("%Y%m%d",
                                                time.localtime()) + '.log'
    logging.basicConfig(filename=log_filename,
                        level=logging.INFO,
                        format=LOG_FORMAT)

    # 当前脚本所在目录路径
    curpath = os.path.dirname(os.path.realpath(__file__))

    # 全局config文件
    global_config = {}
    global_config_file_path = curpath + "/config.yaml"
    if os.path.isfile(global_config_file_path):
        gf = open(global_config_file_path, 'r', encoding='utf-8')
        global_config = yaml.safe_load(gf.read())

    # 是否传入配置文件
    if len(sys.argv) > 1:
        test_filename = sys.argv[1]
        config_file = "/config/" + test_filename + ".yaml"
    else:
        test_filename = 'default'
        config_file = "/config/" + test_filename + '.yaml'

    # yaml配置文件是否存在
    config_file_path = curpath + config_file
    if not os.path.isfile(config_file_path):
        print("配置文件不存在 " + config_file_path)
        return 1

    f = open(config_file_path, 'r', encoding='utf-8')
    config = yaml.safe_load(f.read())

    # 合并配置
    config = Util.recursionMergeTwoDict(global_config, config)

    # 是否开启代理
    is_open_proxy = config.get('BROWSER').get('proxy')
    if is_open_proxy:
        from browsermobproxy import Server
        bmp_path = config.get('BROWSER').get('bmp_path')
        logging.info('开启代理 ' + bmp_path)
        proxy_server = Server(bmp_path)
        proxy_server.start()
        proxy_client = proxy_server.create_proxy()

    browser_type = config.get('BROWSER').get('type')
    if browser_type == 'Firefox':
        options = FirefoxOptions()
        options.page_load_strategy = 'normal'
        if is_open_proxy:
            options.add_argument('--proxy-server={0}'.format(
                proxy_client.proxy))
        browser = webdriver.Firefox(options=options)
    elif browser_type == 'Chrome':
        options = ChromeOptions()
        options.page_load_strategy = 'normal'
        if is_open_proxy:
            options.add_argument('--proxy-server={0}'.format(
                proxy_client.proxy))
        browser = webdriver.Chrome(options=options)
    else:
        print('浏览器' + browser_type + ':类型不支持')
        return False

    logging.info('开始使用 ' + browser_type + ' 浏览器进行自动化测试')

    if is_open_proxy:
        proxy_client.new_har("req",
                             options={
                                 'captureHeaders': True,
                                 'captureContent': True
                             })

    browser.maximize_window()
    # 浏览器等待时间
    # browser.implicitly_wait(10)

    url = config.get('WEBSITE').get('url')
    browser.get(url)
    if is_open_proxy:
        Http.logHar(proxy_client.har)

    # 执行配置的TEST对象
    test = config.get('TEST')
    suite = unittest.TestSuite()
    for key in test:
        menus = Menu.getMenuConfig(config, key)
        try:
            if is_open_proxy:
                test_data = [browser, menus, proxy_client]
            else:
                test_data = [browser, menus]
            suite.addTest(
                ParametrizedTestCase.parametrize(Action,
                                                 'test_menu',
                                                 param=test_data))
        except AssertExcetion:
            print(key + " 断言失败")

    report_file_name = 'reports/' + test_filename + "_" + time.strftime(
        "%Y%m%d", time.localtime()) + '.html'
    fp = open(report_file_name, 'w', encoding='utf-8')
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
                                           title='你的测试报告',
                                           description='使用配置文件:' +
                                           config_file_path + '生成的测试报告')
    runner.run(suite)
    fp.close()

    sleep(5)
    browser.quit()

    if is_open_proxy:
        proxy_client.close()
        proxy_server.stop()
コード例 #11
0
from selenium import webdriver
from selenium.webdriver.common.by import By
import pandas as pd
from selenium.webdriver.firefox.options import Options
from progress.bar import IncrementalBar

from common import save

o = Options()

o.page_load_strategy = 'eager'

driver = webdriver.Firefox(options=o)

def get_page(page_num):
    driver.get(f'https://www.dns-shop.ru/catalog/17a8a01d16404e77/smartfony/?stock=now-today-tomorrow-later-out_of_stock&f[pqc]=68kur-kdf7y-o8r3o-y6ccf-1ccyzc&p={page_num}')

def find_urls():
    return [i.get_attribute('href') + 'characteristics/' \
            for i in driver. \
            find_elements(By.CSS_SELECTOR, '.catalog-product__name.ui-link')]

p_num = 1

get_page(p_num)

temp_link_elements = find_urls()
urls = []

while len(temp_link_elements) > 0:
    urls += temp_link_elements
コード例 #12
0
ファイル: test.py プロジェクト: venhow/pystest
def main():
    global proxy_client, proxy_server
    LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
    log_filename = 'logs/test_' + time.strftime("%Y%m%d",
                                                time.localtime()) + '.log'
    logging.basicConfig(filename=log_filename,
                        level=logging.INFO,
                        format=LOG_FORMAT)

    # 当前脚本所在目录路径
    path = os.path.dirname(os.path.realpath(__file__))

    test_config = TestConfig(path)

    if len(sys.argv) > 1:
        report_name = sys.argv[1]
        if 'ls' == sys.argv[1]:
            files = getFileName(path + '/config/')
            print(Util.pretty(files))
            return
    else:
        report_name = 'default'

    # 获取测试用例数据
    config = test_config.get_test_case(sys.argv)

    # 是否开启代理
    is_open_proxy = config.get('BROWSER').get('proxy')
    if is_open_proxy:
        from browsermobproxy import Server
        bmp_path = config.get('BROWSER').get('bmp_path')
        logging.info('开启代理 ' + bmp_path)
        proxy_server = Server(bmp_path)
        proxy_server.start()
        proxy_client = proxy_server.create_proxy()

    # 浏览器类型
    browser_type = config.get('BROWSER').get('type')

    # 是否使用H5测试,并指定移动设备名称
    h5 = config.get('BROWSER').get('H5', False)
    device_name = config.get('BROWSER').get('device_name', 'iPhone 7')

    # 是否开启无头模式
    headless = config.get('BROWSER').get('headless', False)

    if browser_type == 'Firefox':
        options = FirefoxOptions()
        if headless:
            options.add_argument("-headless")
        options.page_load_strategy = 'normal'
        if h5:
            user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
            options.set_preference("general.useragent.override", user_agent)

        if is_open_proxy:
            options.add_argument('--proxy-server={0}'.format(
                proxy_client.proxy))
        browser = webdriver.Firefox(options=options)
    elif browser_type == 'Chrome':
        options = ChromeOptions()
        if headless:
            options.add_argument("--window-size=1920,1080")  # 设置浏览器分辨率(窗口大小)
            options.add_argument(
                "--start-maximized")  # 最大化运行(全屏窗口),不设置,获取元素可能会报错
            options.add_argument("--disable-extensions")
            options.add_argument('--no-sandbox')  # 取消沙盒模式,浏览器的安全性会降低
            # 禁用GPU加速,降低资源损耗,only for Windows but not a valid configuration for Linux OS
            options.add_argument('--disable-gpu')
            options.add_argument('--disable-dev-shm-usage')  # 解决资源有限的问题
            options.add_argument('--lang=en_US')
            options.add_argument("--headless")
        options.page_load_strategy = 'normal'
        if h5:
            mobileEmulation = {'deviceName': device_name}
            options.add_experimental_option('mobileEmulation', mobileEmulation)

        if is_open_proxy:
            options.add_argument('--proxy-server={0}'.format(
                proxy_client.proxy))
        browser = webdriver.Chrome(options=options)
    else:
        print('浏览器' + browser_type + ':类型不支持')
        return False

    logging.info('开始使用 ' + browser_type + ' 浏览器进行自动化测试')

    if is_open_proxy:
        proxy_client.new_har("req",
                             options={
                                 'captureHeaders': True,
                                 'captureContent': True
                             })

    if browser_type == 'Firefox' and h5:
        browser.set_window_size(360, 640)
    else:
        browser.maximize_window()
    # 浏览器等待时间
    # browser.implicitly_wait(10)

    url = config.get('WEBSITE').get('url')
    browser.get(url)
    if is_open_proxy:
        Http.logHar(proxy_client.har)

    # 执行配置的TEST对象
    test = config.get('TEST')
    suite = unittest.TestSuite()
    m = Menu()
    for key in test:
        menus = m.getMenuConfig(config, key)
        try:
            if is_open_proxy:
                test_data = [browser, menus, proxy_client]
            else:
                test_data = [browser, menus]
            suite.addTest(
                ParametrizedTestCase.parametrize(Action,
                                                 'test_menu',
                                                 param=test_data))
        except AssertExcetion:
            print(key + " 断言失败")

    # 是否生成报告,默认开启调试模式,不生成报告
    debug = config.get('DEBUG', True)
    if debug:
        runner = unittest.TextTestRunner()
        runner.run(suite)
    else:
        # 报告是否含有截图,DEBUG为False且IMAGE设置为True时生效
        image = config.get('IMAGE', False)
        report_path = path + '/reports/'
        report_file = report_name + "_" + time.strftime(
            "%Y%m%d", time.localtime()) + '.html'
        fp = open(report_path + report_file, 'wb')
        report_title = '你的测试报告'
        report_desc = '使用配置:' + report_name + '生成的测试报告'
        runner = HTMLTestRunner(stream=fp,
                                verbosity=2,
                                images=image,
                                title=report_title,
                                description=report_desc,
                                tester='pystest')
        runner.run(suite)
        fp.close()

    sleep(5)
    browser.quit()

    # send mail or not
    mail = config.get('MAIL')
    if not debug and mail and mail.get('SEND'):
        email_title = report_title
        email_content = report_desc
        smtp = Mail(config.get('MAIL'), report_path)
        smtp.connect()
        smtp.login()
        smtp.send(email_title, email_content, report_file)
        smtp.quit()

    if is_open_proxy:
        proxy_client.close()
        proxy_server.stop()
コード例 #13
0
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from time import time
from time import sleep


print("\n Scanning... \n")
firefox_options =   Options()
firefox_options.add_argument("--headless")
firefox_options.page_load_strategy = 'eager'
browser = webdriver.Firefox(options=firefox_options)

browser.get("https://ent.univ-paris13.fr/applications/notes/")
browser.find_element(By.ID, "username").send_keys("12016045")
browser.find_element(By.ID, "password").send_keys("")
browser.find_element(By.ID, "submit").click()
moyenne = browser.find_element_by_class_name('ligneResumeMoyenne').text

def note_loop_check():
    test = True
    keep_checking = "y"
    start = time()
    print("\n Scanning... You will be notified if something comes up ! \n")
    while test and keep_checking=="y":
        moyenne = browser.find_element_by_class_name('ligneResumeMoyenne').text
        test = float(moyenne) == 16.91
        anchor = time()
        if anchor-start > 1200:
            keep_checking = input("Keep scanning for new notes ? (y/n)")