def before_all(context):
    call( [ "killall", "-9", "chrome" ] )
    options = Options()
    options.add_extension(path_to_chrome_extension)
    #options.add_argument("--remote-debugging-port=9222")
    options.add_argument("--start-maximized")
    context.driver = webdriver.Chrome(executable_path=path_to_chrome_driver, chrome_options=options)
Ejemplo n.º 2
0
 def setUpClass(self):
     #self.driver = webdriver.Ie('c:\\local\\bin\\IEDriverServer.exe')
     chrome_options = Options()
     chrome_options.add_argument("--start-maximized")
     #chrome_options.add_argument("--disable-native-events")
     #self.driver = webdriver.Chrome('c:\\local\\bin\\chromedriver.exe',chrome_options=chrome_options)
     self.driver = webdriver.Firefox()
Ejemplo n.º 3
0
def play_video_1(proxy, av):
    # print(i)
    print(proxy)
    # av = "av41724649"
    chrome_options = Options()
    chrome_options.add_argument("--proxy-server=http://{0}".format(proxy))

    drive = webdriver.Chrome(options=chrome_options)
    # drive = webdriver.Chrome()
    av_url = "https://www.bilibili.com/video/{0}/?spm_id_from=333.788.videocard.4".format(av)
    print(av_url)

    # drive.get("https://www.bilibili.com/video/av41724649/")
    try:
        drive.get(av_url)
        video = WebDriverWait(drive, 10, 0.5).until(
            EC.presence_of_element_located((By.XPATH, "//*[@id='bilibiliPlayer']/div[1]/div[1]/div[8]/video")))  # 找到视频
        url = drive.execute_script("return arguments[0].currentSrc;", video)  # 打印视频地址
        print(url)

        print("start")
        drive.execute_script("return arguments[0].play()", video)  # 开始播放
        time.sleep(10)

        print("stop")
        drive.execute_script("return arguments[0].pause()", video)  # 暂停
    except Exception as e:
        print('except: {0}'.format(e))
    finally:
        drive.close()
Ejemplo n.º 4
0
    def take(self, location: Location) -> str:
        """
        Take a screenshot using chrome webdriver.

        Args:
            location: The location of the map's center point.

        Returns:
            The screenshot's full path.

        """
        context: Context = {
            "key": self.api_key,
            "latitude": location.latitude,
            "longitude": location.longitude,
            "zoom": location.zoom,
        }
        map_html = os.path.join(self._tmpdir, "map.html")
        render_template(os.path.join(self._template_dir, "map.j2"), context, map_html)

        options = Options()
        options.set_headless(headless=True)
        driver = webdriver.Chrome(
            executable_path=self.webdriver_path, chrome_options=options
        )
        driver.set_window_size(self.width, self.height)
        driver.get("file://%s" % map_html)
        time.sleep(5)
        self.path = os.path.join(self.output_dir, "map.png")
        driver.save_screenshot(self.path)
        driver.quit()
        return self.path
Ejemplo n.º 5
0
def makeConnection(SERVER, USER, PASSWORD):
    url = 'https://'+SERVER+'/'

    chrome_options = Options() 
    chrome_options.add_argument("--headless") 
    chrome_options.binary_location = '/usr/bin/chromium-browser' 
    driver = webdriver.Chrome(executable_path= os.path.expanduser('~/usr/local/bin/chromedriver') , chrome_options=chrome_options) 
    driver.get(url)
    time.sleep(1)
    driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), '/tmp', 'kk1.png'))


    elemU = driver.find_element_by_name("username")
    #while elemU:
    print("Identifying...")
    elemP = driver.find_element_by_name("password")
    elemU.clear()
    elemU.send_keys(USER)
    elemP.clear()
    elemP.send_keys(PASSWORD)

    driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), '/tmp', 'kk2.png'))

    elemP.send_keys(Keys.RETURN) 
    time.sleep(1)
    #    try: 
    #        elemU = driver.find_element_by_name("username").clear()
    #    except: 
    #        elemU = None

    driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), '/tmp', 'kk3.png'))

    return driver
def login(username, password):
    """
    Using the given username and password, logs into MyNEU through a
    selenium driver (firefox). Returns the driver object
    """
    opts = Options()
    opts.add_argument("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36")

    driver = webdriver.Chrome(chrome_options=opts)
    # Go to the login page
    login_page = driver.get(LOGIN_PAGE)

    # Find the user and password forms
    user_form = driver.find_element_by_id("username")
    pass_form = driver.find_element_by_id("password")

    # Login in with the given credentias
    user_form.send_keys(username)
    pass_form.send_keys(password)

    # Click the login button
    #button_class = driver.find_element_by_class_name("buttons")
    button = driver.find_element_by_class_name("btn-submit")
    button.click()


    # Also change the size so it all works fine
    driver.set_window_size(1280, 800)
    # Return the driver so we can do more with it
    return driver
def instantiate_webdriver(webdriver_class):
    if webdriver_class is Firefox:
        def webdriver_class():
            profile = FirefoxProfile()

            # Make sure Firefox WebDriver addon works, even if it could not be verified
            profile.set_preference('xpinstall.signatures.required', False)
            webdriver = Firefox(profile)
            return webdriver

    elif webdriver_class is Chrome:
        options = ChromeOptions()

        # If popup blocking is enabled spawning new window handles via JavaScript won't work!
        options.add_argument('disable-popup-blocking')
        webdriver_class = functools.partial(webdriver_class, chrome_options=options)
    elif webdriver_class is PhantomJS:
        def webdriver_class():
            webdriver = PhantomJS()
            # Fix Selenium PermissionError when trying to delete PhantomJS cookie files by simply not creating a cookie
            # file.
            webdriver.service._cookie_temp_file = None
            return webdriver

    try:
        return webdriver_class()
    # Selenium raises Exception directly in some WebDriver classes...
    except Exception:
        pytest.skip('WebDriver not available')
Ejemplo n.º 8
0
 def __init__(self, scenario, download_directory=default_download_directory,
              app_host=None, app_port=None, executable_path=None,
              pages=None):
     # Contract
     must_be(download_directory, "download_directory", (type(None), str))
     must_be(app_host, "app_host", (type(None), str))
     must_be(app_port, "app_port", (type(None), Number))
     must_be(executable_path, "executable_path", (type(None), str))
     must_be(pages, "pages", (dict, type(None)))
     # TODO[TJ]: This should be implemented as part of the future contracts
     # library
     if pages is not None:
         for key, value in pages.items():
             must_be(key, "pages key", str)
             must_be(value, "pages value", AppPage)
     #
     self.scenario = scenario
     if download_directory is not None:
         options = ChromeOptions()
         prefs = {"download.default_directory": download_directory}
         options.add_experimental_option('prefs', prefs)
     else:
         options = None
     if app_host is not None:
         self.app_host = app_host
     if app_port is not None:
         self.app_port = app_port
     if executable_path is not None:
         self.executable_path = executable_path
     self.pages = pages
     super(ChromeBrowser, self).__init__(
         executable_path=self.executable_path, chrome_options=options)
     register_exit(self.quit)
Ejemplo n.º 9
0
def start_up():
    global driver
    chrome_options = Options()
    chrome_options.add_argument('load-extension=../')
    print 'Opening a Chrome browser'
    driver = webdriver.Chrome(chrome_options=chrome_options)
    time.sleep(1)
Ejemplo n.º 10
0
def before_feature(context, feature):
    chrome_options = Options()
    if 'headless' in context.tags:
        chrome_options.add_argument("--headless")
    chrome_options.add_argument("--window-size=1024,768")
    context.browser = webdriver.Chrome(
        chrome_options=chrome_options,
        executable_path="/home/sinan/Downloads/selenium/chromedriver")
        # C:\Users\sinan\Downloads\chromedriver_win32_2.0\chromedriver.exe
    context.browser.implicitly_wait(3)


    """ Kullanacağımız değişkenleri setleyelim. """
    context.STOREFRONT = {
        "homepage": "https://www.hepsiburada.com",
        "cart":     "/ayagina-gelsin/sepetim",
        "login":    "******"
    }

    context.CATEGORIES = {
        "uzaktan_kumanda": "/uzaktan-kumandali-arabalar-c-14001244"
    }

    context.LOGIN_INFO = {
        "mail":     "*****@*****.**",
        "password": "******"
    }
Ejemplo n.º 11
0
 def get_driver(self):
     executable_path = self.exec_path
     opts = Options()
     opts.add_argument('--incognito')
     if self.mobile:
         opts.add_argument('user-agent=' + _MOBILE_BROWSER_USER_AGENT)
     return webdriver.Chrome(self.exec_path, chrome_options = opts)
Ejemplo n.º 12
0
def initiateChromeWithSize(width, height, pixelRatio=2.0):
    mobile_emulation = {
    "deviceMetrics": { "width": width, "height": height, "pixelRatio": pixelRatio },
    "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
    chrome_options = Options()
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
    return webdriver.Chrome(chrome_options=chrome_options)
Ejemplo n.º 13
0
    def __init__(self):
        if(platform.system()=="Linux"):
            self.BASE_PATH = os.path.dirname(os.path.realpath(__file__))
            self.CHROMEDRIVER_PATH = r"%s/libs/selenium_drivers/chromedriver" % (self.BASE_PATH)
            self.WINDOW_SIZE = "1920,1080"

            self.chrome_options = Options()  
            self.chrome_options.add_argument("--headless") 
            self.chrome_options.add_argument("--no-sandbox")
            self.chrome_options.add_argument("--disable-dev-shm-usage") 
            self.chrome_options.add_argument("--window-size=%s" % self.WINDOW_SIZE)

        elif(platform.system()=="Windows"):
            self.BASE_PATH = os.path.dirname(os.path.realpath(__file__))
            self.CHROMEDRIVER_PATH = r"%s/libs/selenium_drivers/chromedriver.exe" % (self.BASE_PATH)
            self.WINDOW_SIZE = "1920,1080"

            self.chrome_options = Options()
            self.chrome_options.add_argument("--headless")
            self.chrome_options.add_argument("--window-size=%s" % self.WINDOW_SIZE)

        self.driver = webdriver.Chrome(
            executable_path=self.CHROMEDRIVER_PATH,
            chrome_options=self.chrome_options
        )
def test_home():
	#driver = webdriver.Chrome() #for Mac OS

	option = Options()
	option.add_argument("headless")
	driverPath = os.getcwd() + '/chromedriver'
	driver = webdriver.Chrome(driverPath, options=option)

	driver.get("http://162.246.157.117:8000/")
	main_elems = [] 
	elem_names = ["name", "about", "skills", "milk", "education", "butter", "work", "contact"] # testing list
	#elem_names = ["name", "about", "skills", "education", "work", "contact"] # actual list

	for name in elem_names:
		try:
			find_elem(name, driver)
			main_elems.append((True, name,))
		except NoSuchElementException:
			main_elems.append((False, name,))

	for each in main_elems:
		try:
			assert each[0] != False
		except AssertionError:
			print("Missing " + each[1] + "; " + each[1] + " must exist.")
Ejemplo n.º 15
0
def get_games_id(comp):

    dates = [d for d in date_range(START_DATE, END_DATE)]
    games_id = []

    chrome_options = Options()
    chrome_options.add_argument('--dns-prefetch-disable')
    driver = Chrome(chrome_options=chrome_options)

    for day in dates:
        driver.get(
            'http://www.espn.com.ar/futbol/resultados/_/liga/{}/fecha/{}'.
            format(comp, day)
        )

        game_link_driver = driver.find_elements_by_class_name(
            'mobileScoreboardLink  '
        )

        for game_driver in game_link_driver:
            game_id = game_driver.get_attribute('href')[46:53]
            games_id.append((game_id, day))

        driver.quit

    # print(games_id)
    return games_id
 def getDriver(self, browser, local=False):
     if browser == "firefox":
         cap = DesiredCapabilities.FIREFOX
     if browser == "ie":
         cap = DesiredCapabilities.INTERNETEXPLORER
     if browser == "chrome":
         cap = DesiredCapabilities.CHROME
         options = Options()
         options.add_argument("--disable-extensions")
         options.add_argument("test-type")
     if browser == "mobile chrome":
         cap = {}
         cap['browserName'] = "Chrome"
         cap['platformName'] = "Android"
         cap['deviceName'] = "android"
     if browser == "android":
         cap = {}
         cap['browserName'] = "Browser"
         cap['platformName'] = "Android"
         cap['deviceName'] = "android"
     if local:
       return webdriver.Chrome()
     else:
       return webdriver.Remote(
                               command_executor='http://10.238.242.50:4444/wd/hub',
                               desired_capabilities=cap
                              )
Ejemplo n.º 17
0
 def _new_webdriver(self, browser=None, *args, **kwargs):
     browser = self.expand_browser_name(browser)
     # Setup display before creating the browser
     self.setup_display()
     def append_service_arg(arg):
         service_args = kwargs.get('service_args', [])
         service_args.append(arg)
         kwargs['service_args'] = service_args
     if browser == 'PhantomJS':
         append_service_arg('--ignore-ssl-errors=true')
     if (browser == 'Firefox'
     and self.global_settings.get('webdriver_firefox_profile')
     and not args and not kwargs.has_key('firefox_profile')):
         # Update with profile specified from config
         fp = webdriver.FirefoxProfile(self.global_settings.get('webdriver_firefox_profile'))
         kwargs['firefox_profile'] = fp
     if (browser == 'Chrome' and os.name == 'posix' and os.geteuid() == 0):
         self.log.w('Passing --no-sandbox flag to Chrome (running as root)')
         from selenium.webdriver.chrome.options import Options
         chrome_options = Options()
         chrome_options.add_argument('--no-sandbox')
         #self.log.w('Adding --disable-application-cache')
         #chrome_options.add_argument('--disable-application-cache')
         #chrome_options.add_argument('--incognito')
         kwargs['chrome_options'] = chrome_options
     driver = getattr(webdriver, browser)(*args, **kwargs)
     return driver
Ejemplo n.º 18
0
def loginToInterface(isMac, chrome, driver, host, port=8686, username='******', password='******'):
    logCommon.info('Will start web browser and perform test case.')
    chromeDriver = os.path.normpath(driver)
    logCommon.info('Browser driver path: ' + str(chromeDriver))
    os.environ["webdriver.chrome.driver"] = chromeDriver
    opts = Options()
    if (not isMac):
        opts = Options()
        opts.binary_location = os.path.normpath(chrome)
    else:
        opts.add_argument("--start-maximized")
    driver = webdriver.Chrome(chromeDriver, chrome_options=opts)
    # options.add_argument("--start-maximized")
    # driver.set_window_size(1024, 600)
    driver.maximize_window()
    # go to the google home page
    index = 'http://' + str(host) + ':' + str(port) + '/XOAM/login/index.html'
    logCommon.info('Web page: ' + str(index))
    driver.get(index)
    driver.find_element_by_id('loginUsername').clear()
    driver.find_element_by_id('loginUsername').send_keys(username)
    driver.find_element_by_id('loginPassword').clear()
    driver.find_element_by_id('loginPassword').send_keys(password)
    driver.find_element_by_id('submit').click()
    try:
        WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "ebBtnSearch")))
        logCommon.info('Login to the InterfaceManagement page successfully.')
    except Exception as e:
        logCommon.error('Login to the InterfaceManagement page failed.')
        return False
    return driver
Ejemplo n.º 19
0
    def newDriver():
        if os.getenv('TRAVIS') == 'true':
            options = Options()
            options.add_argument("--no-sandbox")
            return webdriver.Chrome(chrome_options=options)

        return webdriver.Chrome()
Ejemplo n.º 20
0
def findSnItemPrice(itemId):
  itemUrl = urlTemplate.replace('{itemId}', str(itemId))
  #print("itemUrl=%s" % itemUrl)
  

  #driver = webdriver.PhantomJS()
  chrome_options = Options()
  chrome_options.add_argument('--headless')
  chrome_options.add_argument('--disable-gpu')
  driver = webdriver.Chrome(chrome_options=chrome_options)
  driver.get(itemUrl)
  html = driver.page_source
  #print(html)  

  bsObj = BeautifulSoup(html,"html.parser")
  priceList=bsObj.findAll("span",{"class":"mainprice"})  
  itemNameList = bsObj.findAll("h1", {"id":"itemDisplayName"})
  itemName = itemNameList[0].get_text()
  promDescList = bsObj.findAll("h2", {"id":"promotionDesc"})
  promDesc = promDescList[0].get_text()
  #print(priceList)
  #print(itemNameList)
  if len(priceList)>0:
    for price in priceList:  
      strPrice = price.get_text().replace('¥','').replace('.00','')
      print("itemId=%s,price:%d,itemName:%s,promDesc:%s" % (itemId,int(strPrice), itemName, promDesc))
  else:
      strPrice = "-1"
      print("itemId=%s,price:%d,itemName:%s,promDesc:%s" % (itemId,int(strPrice), itemName, promDesc))
Ejemplo n.º 21
0
def launch_browser():

    if env.RUNNING_BROWSER.upper() == "FIREFOX":
        # the end of the browser process , the end of the browser driven process
        os.popen("TASKKILL /F /IM firefoxdriver.exe")

        fp = FirefoxProfile()
        fp.native_events_enabled = False

        binary_path = PublicImp.common.get_value_from_conf("FIREFOX_BINARY_PATH")

        if binary_path == "":
            env.driver = selenium.webdriver.Firefox(firefox_profile=fp)
        else:
            fb = FirefoxBinary(firefox_path=binary_path)
            env.driver = selenium.webdriver.Firefox(firefox_profile=fp, firefox_binary=fb)

    elif env.RUNNING_BROWSER.upper() == "CHROME":
        os.popen("TASKKILL /F /IM chromedriver.exe")

        binary_path = PublicImp.common.get_value_from_conf("CHROME_BINARY_PATH")
        chromedriver = PublicImp.common.get_value_from_conf("DRIVER_CHROME")

        if binary_path == "":
            os.environ["webdriver.chrome.driver"] = chromedriver
            env.driver = selenium.webdriver.Chrome(executable_path=chromedriver)
        else:
            opts = Options()
            opts.binary_location = binary_path
            os.environ["webdriver.chrome.driver"] = chromedriver
            env.driver = selenium.webdriver.Chrome(executable_path=chromedriver, chrome_options=opts)

    elif env.RUNNING_BROWSER.upper() == "IE":
        os.popen("TASKKILL /F /IM IEDriverServer.exe")

        dc = DesiredCapabilities.INTERNETEXPLORER.copy()

        dc['acceptSslCerts'] = True
        dc['nativeEvents'] = True

        iedriver = PublicImp.common.get_value_from_conf("DRIVER_IE")
        os.environ["webdriver.ie.driver"] = iedriver
        env.driver = selenium.webdriver.Ie(executable_path=iedriver, capabilities=dc)

    else:
        return False

    env.platformName = env.RUNNING_BROWSER

    env.TEST_URL = PublicImp.common.get_value_from_conf("TESTING_URL")
    env.driver.get(env.TEST_URL)
    env.driver.maximize_window()

    time.sleep(3)
    env.driver.refresh()
    # env.driver.set_window_size(480, 800)
    time.sleep(3)

    return True
Ejemplo n.º 22
0
 def get_chrome_driver(self):
     opts = Options()
     if "TRAVIS" in os.environ:  # github.com/travis-ci/travis-ci/issues/938
         opts.add_argument("--no-sandbox")
     # Fix for https://code.google.com/p/chromedriver/issues/detail?id=799
     opts.add_experimental_option("excludeSwitches",
                                  ["ignore-certificate-errors"])
     return webdriver.Chrome(chrome_options=opts)
Ejemplo n.º 23
0
def create_chrome_driver():
	chrome_options = Options()
	for setting in settings.DEFAULT_REQUEST_HEADERS:
		chrome_options.add_argument(''.join((setting, '="', settings.DEFAULT_REQUEST_HEADERS[setting], '"')))

	chrome = webdriver.Chrome(executable_path=chrome_path, chrome_options=chrome_options)
	chrome.fullscreen_window()
	return chrome
Ejemplo n.º 24
0
def webdriver_options():
    options = Options()
    options.add_argument('--no-sandbox')

    if os.environ.get('SHOW_BROWSER') != '1':
        options.add_argument('--headless')

    return options
Ejemplo n.º 25
0
def create_page():
	chrome_options = Options()
	chrome_options.add_argument("--disable-extensions")
	chrome_options.add_argument("--start-maximized")

	driver = webdriver.Chrome(chrome_options = chrome_options)
	driver.get("https://www.mousehuntgame.com")
	return driver
Ejemplo n.º 26
0
def hangout_factory():
    if os.environ.get('DISPLAY'):
        del os.environ['DISPLAY']
    chrome_options = Options()
    if 'TRAVIS' in os.environ:
        chrome_options.add_argument('--no-sandbox')
    hangout = Hangouts(chrome_options=chrome_options)
    # hangout.browser.timeout = 60
    return hangout
Ejemplo n.º 27
0
 def setUp(self):
     chrome_options = Options()
     chrome_options.add_argument("--lang=en")
     chrome_options.add_argument("--window-size=1277,744")
     self.driver = webdriver.Chrome(chrome_options=chrome_options)
     self.driver.implicitly_wait(30)
     self.base_url = base_url
     self.verificationErrors = []
     self.accept_next_alert = True
Ejemplo n.º 28
0
 def __init__driver__():
     mOptions = Options()
     mOptions.add_argument("user-data-dir=./chromeSettings/")
     ChromeFacebook.cDriver = webdriver.Chrome(chrome_options=mOptions)
     ChromeFacebook.SCREEN_WIDTH = ChromeFacebook.cDriver.execute_script("return screen.width;")
     ChromeFacebook.SCREEN_HEIGHT = ChromeFacebook.cDriver.execute_script("return screen.height;")
     ChromeFacebook.cDriver.set_window_position(0,0)
     ChromeFacebook.cDriver.set_window_size(ChromeFacebook.SCREEN_WIDTH, ChromeFacebook.SCREEN_HEIGHT)
     ChromeFacebook.cDriver.get('http://www.facebook.com')
Ejemplo n.º 29
0
 def setUp(self):
     # Firefox
     options_firefox = OptionsFF()
     options_firefox.add_argument('-headless')
     self.firefox_driver = webdriver.Firefox(firefox_options=options_firefox)
     # Chrome
     options_chrome = OptionsChrom()
     options_chrome.add_argument('-headless')
     self.chrome_driver = webdriver.Chrome(chrome_options=options_chrome)
Ejemplo n.º 30
0
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chromeOptions = Options()
chromeOptions.add_experimental_option(
    "prefs",
    {"download.default_directory": "C:\\Users\\minds9\\Desktop\\Py_downloads"})

driver = webdriver.Chrome(
    executable_path=
    "C:\\Users\\minds9\\PycharmProjects\\Python_Selenium\\drivers\\chromedriver.exe",
    chrome_options=chromeOptions)

driver.get("http://pypi.python.org/pypi/selenium")
driver.maximize_window()
driver.implicitly_wait(10)

driver.find_element_by_xpath("//a[@id='files-tab']").click()
time.sleep(2)
driver.find_element_by_xpath(
    "//a[contains(text(),'selenium-3.141.0-py2.py3-none-any.whl')]").click()
Ejemplo n.º 31
0
import time

from selenium import webdriver as wb
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.options import Options

ops = Options()
ops.add_experimental_option('excludeSwitches', ['enable-automation'])
ops.add_argument('--proxy-server=http://192.168.1.121:8080')
browser = wb.Chrome(chrome_options=ops, )
# browser = wb.Remote(
#             command_executor="http://192.168.1.63:32100/wd/hub",
#             desired_capabilities=DesiredCapabilities.CHROME,
#             options=ops
#         )
browser.get(url='http://mitm.it')
time.sleep(30)
browser.close()
Ejemplo n.º 32
0
import json

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--window-size=1280x1696')
chrome_options.add_argument('--user-data-dir=/tmp/user-data')
chrome_options.add_argument('--hide-scrollbars')
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--log-level=0')
chrome_options.add_argument('--v=99')
chrome_options.add_argument('--single-process')
chrome_options.add_argument('--data-path=/tmp/data-path')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--homedir=/tmp')
chrome_options.add_argument('--disk-cache-dir=/tmp/cache-dir')
chrome_options.add_argument('user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36')
chrome_options.binary_location = os.getcwd() + "/bin/headless-chromium"

driver = webdriver.Chrome(chrome_options=chrome_options)


def handler(event, context):
    body = {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "input": event
Ejemplo n.º 33
0
# This Python file uses the following encoding: utf-8
import os
import openpyxl
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.alert import Alert
from openpyxl import workbook
import xlrd
import xlwt
from xlutils.copy import copy
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException

wb = xlwt.Workbook(encoding='utf-8')
sheet = wb.add_sheet('write wb sheet name')

chrome_options = Options()
chrome_options.add_argument("disable-gpu")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("test-type")
driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)

j = 0

for startnum in range(startnumber,
                      finishnubmer):  # need to write number for set range
    driver.get(
        "http://store-kr.uniqlo.com/display/showDisplayCache.lecs?goodsNo=NQ%d"
        % startnum)
    try:
        alert = driver.switch_to_alert()
        alert.accept()
Ejemplo n.º 34
0
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from time import sleep

chromeDriver ='driver/chromedriverMac'
chrome_options = Options()
driver = webdriver.Chrome(chromeDriver, options=chrome_options)

sleep(1)
driver.get('https://web.whatsapp.com')
sleep(17)

def sendMessage(name,message):
    input_box = driver.find_element_by_css_selector("._2S1VP")
    input_box.click()
    input_box.send_keys(name + Keys.ENTER)
    sleep(1)
    inputbox = driver.find_element_by_css_selector("div[data-tab='1']")
    inputbox.click()
    sleep(1)
    inputbox.send_keys(message)
    send_button = driver.find_element_by_css_selector("span[data-icon='send']")
    sleep(1)
    send_button.click()

sendMessage("Javas","Hi, this messahe from Python ")
sleep(1)
sendMessage("Javas","Using Selenium and ChromeDriver")
sleep(1)
sendMessage("Javas","Thanks ...")
Ejemplo n.º 35
0
import os
import re
import sys
import time
from bs4 import BeautifulSoup
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options



options = Options()
options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
driver = webdriver.Chrome(os.path.join(os.getcwd(), "chromedriver"))

def read_gpx():
    cwd = os.getcwd()
    with open(cwd, 'r') as f:
        yield f


def upload_gpx_to_strava(gpx_names):
    
    for i, gpx_name in enumerate(gpx_names):
        driver.get('https://labs.strava.com/gpx-to-route/#12/-122.44503/37.73651')

        driver.find_element_by_id("gpxFile").send_keys(os.path.join(os.getcwd(), gpx_name))

        time.sleep(15)

        if i == 0:
Ejemplo n.º 36
0
def scrape(artist, song):
    t = datetime.now().second

    similars = {}
    urls = []
    opts = Options()
    opts.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
    opts.add_argument("start-maximized")
    opts.add_argument("--disable-dev-shm-usage")
    opts.add_argument("--no-sandbox")
    opts.add_argument('disable-infobars')
    opts.add_argument("--disable-extensions")
    opts.add_argument('--headless')
    driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), options=opts)
    driver.get("https://genius.com/{}-{}-lyrics".format("-".join(artist.split()), "-".join(song.split())))
    
    label = driver.find_elements_by_class_name("metadata_unit-label")
    info = driver.find_elements_by_class_name("metadata_unit-info")
    relevant_info = "Artist, Produced by, Written By, Mixing Engineer".lower().split(', ')

    for l, i in zip(label, info):
        soup = bs(i.get_attribute('innerHTML'), 'html.parser')
        if(l.text.lower() in relevant_info):
            urls += [i.attrs['href'] for i in soup.find_all('a')]
        if(abs(t - datetime.now().second) > 12):
            break
    urls = list(set(urls))

    for url in urls:
        driver.get(url)
        songs = driver.find_elements_by_class_name("mini_card-title")
        artists = driver.find_elements_by_class_name("mini_card-subtitle")
        for i,j in zip(songs, artists):
            if(i.text.lower() != song.lower()):
                similars[j.text.split(', ')[0]] = i.text
        if(abs(t - datetime.now().second) > 20):
            break

    driver.close()

    sims = pd.DataFrame(similars.values(), similars.keys()).reset_index()
    if(sims.shape[0] == 0):
        return "Timeout error."
    sims.columns = ['Artist', 'Song']
    return sims.to_string(index=False)
Ejemplo n.º 37
0
 def get_session(self):
     mainPath = os.getcwd()
     downloadFilepath = os.path.normpath(downloadFileFolder)
     self.downloadDir = downloadFilepath
     if self.local:
         chrome_options = Options()
         #os.makedirs(downloadFilepath)
         mainPath = os.getcwd()
         downloadFilepath = os.path.normpath(downloadFileFolder)
         print(downloadFilepath + "yoo")
         preferences = {
             "profile.default_content_settings.popups": 0,
             'profile.default_content_setting_values.automatic_downloads':
             1,
             "download.default_directory": downloadFilepath,
             "download.prompt_for_download": False
         }  #,"directory_upgrade": True,"safebrowsing.enabled": True }
         chrome_options.add_experimental_option("prefs", preferences)
         self.driver = webdriver.Chrome(
             executable_path='/home/oulu/usr/chromedriver.exe',
             chrome_options=chrome_options)
         str1 = ''
         if 'browserVersion' in self.driver.capabilities:
             str1 = self.driver.capabilities['browserVersion']
         else:
             str1 = self.driver.capabilities['version']
             str2 = self.driver.capabilities['chrome'][
                 'chromedriverVersion'].split(' ')[0]
         print(str1)
         print(str2)
         print(str1[0:2])
         print(str2[0:2])
         if str1[0:2] != str2[0:2]:
             print("please download correct chromedriver version")
     else:
         chrome_options = Options()
         chrome_options.add_argument("--headless")
         chrome_options.add_argument("--window-size=1920x1080")
         chrome_options.add_argument("--disable-notifications")
         chrome_options.add_argument('--no-sandbox')
         chrome_options.add_argument('--verbose')
         #chrome_options.add_argument('--remote-debugging-port=9222')
         chrome_options.add_experimental_option(
             "prefs", {
                 "download.default_directory": downloadFilepath,
                 "download.prompt_for_download": False,
                 "download.directory_upgrade": True,
                 "safebrowsing_for_trusted_sources_enabled": False,
                 "safebrowsing.enabled": False
             })
         chrome_options.add_argument('--disable-gpu')
         #chrome_options.add_argument('--disable-software-rasterizer')
         # initialize driver object and change the <path_to_chrome_driver> depending on your directory where your chromedriver should be
         self.driver = webdriver.Chrome(
             executable_path='/usr/bin/chromedriver',
             options=chrome_options)
         # change the <path_to_place_downloaded_file> to your directory where you would like to place the downloaded file
         download_dir = downloadFilepath
         # function to handle setting up headless download
         self.enable_download_headless(download_dir)
         self.driver.get(self.url)
         self.driver.implicitly_wait(60)
         #self.driver.maximize_window()
         #self.driver.implicitly_wait(30)
         self.driver.get(self.url)
         return self.driver
def lambda_handler(event, context):

    #Prepare Chrome Options
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--window-size=1280x1696')
    chrome_options.add_argument('--user-data-dir=/tmp/user-data')
    chrome_options.add_argument('--hide-scrollbars')
    chrome_options.add_argument('--enable-logging')
    chrome_options.add_argument('--log-level=0')
    chrome_options.add_argument('--v=99')
    chrome_options.add_argument('--single-process')
    chrome_options.add_argument('--data-path=/tmp/data-path')
    chrome_options.add_argument('--ignore-certificate-errors')
    chrome_options.add_argument('--homedir=/tmp')
    chrome_options.add_argument('--disk-cache-dir=/tmp/cache-dir')
    chrome_options.add_argument(
        'user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
    )
    chrome_options.binary_location = os.getcwd() + "/bin/headless-chromium"

    #Launch Headless Chrome
    driver = webdriver.Chrome(chrome_options=chrome_options)

    #Configure query params
    tracking = event['tracking']
    function = event['carrier']

    #Execute function test on specified carrier
    f = carrier_dict[function](tracking, driver)

    driver.close()
    driver.quit()

    # If tracking number matches carrier, return carrier url
    if f != False:
        return {'statusCode': 200, 'body': f}
    #Otherwise, return false
    return {'statusCode': 200, 'body': json.dumps(False)}
 def __init__(self):
     options = Options()
     options.add_argument('--headless')
     options.add_argument('--incognito')
     self.driver = webdriver.Chrome(options=options)
Ejemplo n.º 40
0
async def carbon_api(e):
    RED = random.randint(0, 256)
    GREEN = random.randint(0, 256)
    BLUE = random.randint(0, 256)
    THEME = [
        "3024-night",
        "a11y-dark",
        "blackboard",
        "base16-dark",
        "base16-light",
        "cobalt",
        "dracula",
        "duotone-dark",
        "hopscotch",
        "lucario",
        "material",
        "monokai",
        "night-owl",
        "nord",
        "oceanic-next",
        "one-light",
        "one-dark",
        "panda-syntax",
        "paraiso-dark",
        "seti",
        "shades-of-purple",
        "solarized",
        "solarized%20light",
        "synthwave-84",
        "twilight",
        "verminal",
        "vscode",
        "yeti",
        "zenburn",
    ]
    CUNTHE = random.randint(0, len(THEME) - 1)
    The = THEME[CUNTHE]
    cat = await edit_or_reply(e, "⬜⬜⬜⬜⬜")
    CARBON = "https://carbon.now.sh/?bg=rgba({R}%2C{G}%2C{B}%2C1)&t={T}&wt=none&l=auto&ds=false&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Fira%20Code&fs=14px&lh=152%25&si=false&es=2x&wm=false&code={code}"
    CARBONLANG = "en"
    textx = await e.get_reply_message()
    pcode = e.text
    if pcode[7:]:
        pcode = str(pcode[7:])
    elif textx:
        pcode = str(textx.message)  # Importing message to module
    code = quote_plus(pcode)  # Converting to urlencoded
    url = CARBON.format(code=code,
                        R=RED,
                        G=GREEN,
                        B=BLUE,
                        T=The,
                        lang=CARBONLANG)
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.binary_location = Config.CHROME_BIN
    chrome_options.add_argument("--window-size=1920x1080")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-gpu")
    prefs = {"download.default_directory": "./"}
    chrome_options.add_experimental_option("prefs", prefs)
    await cat.edit("⬛⬛⬜⬜⬜")

    driver = webdriver.Chrome(executable_path=Config.CHROME_DRIVER,
                              options=chrome_options)
    driver.get(url)
    download_path = "./"
    driver.command_executor._commands["send_command"] = (
        "POST",
        "/session/$sessionId/chromium/send_command",
    )
    params = {
        "cmd": "Page.setDownloadBehavior",
        "params": {
            "behavior": "allow",
            "downloadPath": download_path
        },
    }
    driver.execute("send_command", params)
    driver.find_element_by_xpath("//button[contains(text(),'Export')]").click()
    await asyncio.sleep(2)  # this might take a bit.
    #  driver.find_element_by_xpath("//button[contains(text(),'4x')]").click()
    # await asyncio.sleep(5)
    await cat.edit("⬛⬛⬛⬜⬜")
    # driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click()
    await asyncio.sleep(2)  # Waiting for downloading
    await cat.edit("⬛⬛⬛⬛⬛")
    file = "./carbon.png"
    await cat.edit("✅RGB Karbon Completed, Uploading Karbon✅")
    await e.client.send_file(
        e.chat_id,
        file,
        caption=f"Here's your karbonrgb",
        force_document=True,
        reply_to=e.message.reply_to_msg_id,
    )
    os.remove("./carbon.png")
    await cat.delete()  # Deleting msg
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
import time
import loginInfo
import os

options = Options()
options.add_argument("--window-size=1920x1080")
options.add_argument("--incognito")
chromedriver_path = './chromedriver'

f = open("follow_req.txt", "w")

browser = webdriver.Chrome(executable_path=chromedriver_path,
                           options=options)  #Star Browser

browser.get("https://www.instagram.com/")

time.sleep(3)  #Waiting 3 seconds after we open the page.

#IG Login -->

username = browser.find_element_by_name("username")
username.send_keys(loginInfo.username)

password = browser.find_element_by_name("password")
password.send_keys(loginInfo.password)

login_button = browser.find_element_by_xpath("//button[@type='submit']")
login_button.click()
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
#chrome_options.add_argument("--headless")
chrome_options.binary_location = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'

driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"),
                          chrome_options=chrome_options)
driver.get("http://192.168.99.100:30080")  # gitlab

time.sleep(180)
#print(driver.page_source)
while "create a password" not in driver.page_source:
    driver.get("http://192.168.99.100:30080")
    time.sleep(30)
    print("checking if gitlab is up")
    #pass

pass_field = driver.find_element_by_id("user_password")
pass_conf_field = driver.find_element_by_id("user_password_confirmation")
pass_field.clear()
pass_conf_field.clear()
pass_field.send_keys("GitPass1!")
pass_conf_field.send_keys("GitPass1!")
pass_conf_field.send_keys(Keys.RETURN)
#assert "This field is required" in driver.page_source
driver.close()
Ejemplo n.º 43
0
def chromeConfig():
    ## Driver Path
    chromedriverPath = "C:\web_project\WholethingAPI\wholeThingAPI\wholething\wholethingAPI\Driver/chromedriver.exe"

    WINDOW_SIZE = "1920,1080"
    chrome_options = Options()
    chrome_options.add_argument("--headless")  # 크롬창이 열리지 않음
    chrome_options.add_argument(
        "--no-sandbox")  # GUI를 사용할 수 없는 환경에서 설정, linux, docker 등
    chrome_options.add_argument(
        "--disable-gpu")  # GUI를 사용할 수 없는 환경에서 설정, linux, docker 등
    chrome_options.add_argument(f"--window-size={ WINDOW_SIZE }")
    chrome_options.add_argument('Content-Type=application/json; charset=utf-8')

    driver = webdriver.Chrome(executable_path=chromedriverPath,
                              chrome_options=chrome_options)

    return driver
Ejemplo n.º 44
0
#! /usr/bin/env python
# coding: utf-8

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException

chrome_options = Options()
chrome_options.add_argument("--headless")

driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver',
                          chrome_options=chrome_options)
driver.get('http://news.joins.com/DigitalSpecial/298')
sel1 = driver.find_element_by_id('selDepth1')
#it can't use click method : https://stackoverflow.com/questions/27927964/selenium-element-not-visible-exception?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
#sel1.click()
driver.execute_script("document.querySelectorAll('#selDepth1')[0].click()")
sel1_items = sel1.find_elements_by_xpath('div//div')

# skip first item
for pos1, item1 in enumerate(sel1_items[1:], 1):
    #item1.click()
    driver.execute_script(
        "document.querySelectorAll('#selDepth1 > div > div')[" + str(pos1) +
        "].click()")
    item1text = item1.get_attribute('innerHTML')
    sel2 = driver.find_element_by_id('selDepth2')
    #sel2.click()
    driver.execute_script("document.querySelectorAll('#selDepth2')[0].click()")
    sel2_items = sel2.find_elements_by_xpath('div//div')
Ejemplo n.º 45
0
class PeopleCheck(object):
    """A class containing the tools for performing OSINT for people."""

    # Headers for use with Requests
    user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"
    headers = {'User-Agent' : user_agent}

    def __init__(self):
        """Everything that should be initiated with a new object goes here."""
        # Collect the API keys from the config file
        try:
            consumer_key = helpers.config_section_map("Twitter")["consumer_key"]
            consumer_key_secret = helpers.config_section_map("Twitter")["key_secret"]
            access_token = helpers.config_section_map("Twitter")["access_token"]
            access_token_secret = helpers.config_section_map("Twitter")["token_secret"]
            twit_auth = tweepy.OAuthHandler(consumer_key, consumer_key_secret)
            twit_auth.set_access_token(access_token, access_token_secret)
            self.twit_api = tweepy.API(twit_auth, timeout=10)
        except Exception:
            self.twit_api = None
            print(yellow("[!] Could not setup OAuth for Twitter API."))

        try:
            self.emailhunter_api_key = helpers.config_section_map("EmailHunter")["api_key"]
        except Exception:
            self.emailhunter_api_key = ""
            print(yellow("[!] Could not fetch EmailHunter API key."))

        try:
            self.contact_api_key = helpers.config_section_map("Full Contact")["api_key"]
        except Exception:
            self.contact_api_key = ""
            print(yellow("[!] Could not fetch Full Contact API key."))

        try:
            self.chrome_driver_path = helpers.config_section_map("WebDriver")["driver_path"]
            # Try loading the driver as a test
            self.chrome_options = Options()
            self.chrome_options.add_argument("--headless")
            self.chrome_options.add_argument("--window-size=1920x1080")
            self.browser = webdriver.Chrome(chrome_options=self.chrome_options, executable_path=self.chrome_driver_path)
        # Catch issues with the web driver or path
        except WebDriverException:
            self.chrome_driver_path = None
            self.browser = webdriver.PhantomJS()
            print(yellow("[!] There was a problem with the specified Chrome web driver in your \
keys.config! Please check it. For now ODIN will try to use PhantomJS for HaveIBeenPwned."))
        # Catch issues loading the value from the config file
        except Exception:
            self.chrome_driver_path = None
            self.browser = webdriver.PhantomJS()
            print(yellow("[!] Could not load a Chrome webdriver for Selenium, so we will tryuse \
to use PantomJS for haveIBeenPwned."))

    def pwn_check(self, email):
        """Use HIBP's API to check for the target's email in public security breaches."""
        try:
            self.browser.get('https://haveibeenpwned.com/api/v2/breachedaccount/{}'.format(email))
            # cookies = browser.get_cookies()
            json_text = self.browser.find_element_by_css_selector('pre').get_attribute('innerText')
            pwned = json.loads(json_text)

            return pwned
        except TimeoutException:
            print(red("[!] Connectionto HaveIBeenPwned timed out!"))
            return []
        except NoSuchElementException:
            # This is likely an "all clear" -- no hits in HIBP
            return []
        except WebDriverException:
            # print(red("[!] Connectionto HaveIBeenPwned timed out!"))
            return []

    def paste_check(self, email):
        """Use HIBP's API to check for the target's email in pastes across multiple paste websites.
        This includes sites like Slexy, Ghostbin, Pastebin.
        """
        try:
            self.browser.get('https://haveibeenpwned.com/api/v2/pasteaccount/{}'.format(email))
            # cookies = browser.get_cookies()
            json_text = self.browser.find_element_by_css_selector('pre').get_attribute('innerText')
            pastes = json.loads(json_text)

            return pastes
        except TimeoutException:
            print(red("[!] Connectionto HaveIBeenPwned timed out!"))
            return []
        except NoSuchElementException:
            # This is likely an "all clear" -- no hits in HIBP
            return []
        except WebDriverException:
            # print(red("[!] Connectionto HaveIBeenPwned timed out!"))
            return []

    def full_contact_email(self, email):
        """Use the Full Contact API to collect social information for the target email address."""
        # TODO: Implement the use of the People API -- Also, update this for v3 of the API.
        if self.contact_api_key is None:
            print(red("[!] No Full Contact API key, so skipping these searches."))
        else:
            base_url = "https://api.fullcontact.com/v2/person.json"
            payload = {'email':email, 'apiKey':self.contact_api_key}
            resp = requests.get(base_url, params=payload)
            if resp.status_code == 200:
                return resp.json()

    def full_contact_company(self, domain):
        """Use the Full Contact API to collect company profile information for the target domain."""
        if self.contact_api_key is None:
            print(red("[!] No Full Contact API key, so skipping company lookup."))
            return None
        else:
            base_url = "https://api.fullcontact.com/v3/company.enrich"
            headers = {"Authorization":"Bearer %s" % self.contact_api_key}
            payload = {'domain':domain}
            resp = requests.post(base_url, data=json.dumps(payload), headers=headers)
            if resp.status_code == 200:
                return resp.json()

    def harvest_all(self, domain):
        """Use TheHarvester to discover email addresses and employee names."""
        # Set the search configuration for TheHarvester
        harvest_limit = 100
        harvest_start = 0

        print(green("[+] Beginning the harvesting of email addresses for {}...".format(domain)))
        # Search through most of Harvester's supported engines
        # No Baidu because it always seems to hang or take way too long
        print(green("[*] Harvesting Google"))
        search = googlesearch.search_google(domain, harvest_limit, harvest_start)
        search.process()
        google_harvest = search.get_emails()

        print(green("[*] Harvesting LinkedIn"))
        search = linkedinsearch.search_linkedin(domain, harvest_limit)
        search.process()
        link_harvest = search.get_people()

        print(green("[*] Harvesting Twitter"))
        search = twittersearch.search_twitter(domain, harvest_limit)
        search.process()
        twit_harvest = search.get_people()

        print(green("[*] Harvesting Yahoo"))
        search = yahoosearch.search_yahoo(domain, harvest_limit)
        search.process()
        yahoo_harvest = search.get_emails()

        print(green("[*] Harvesting Bing"))
        search = bingsearch.search_bing(domain, harvest_limit, harvest_start)
        search.process('no')
        bing_harvest = search.get_emails()

        print(green("[*] Harvesting Jigsaw"))
        search = jigsaw.search_jigsaw(domain, harvest_limit)
        search.process()
        jigsaw_harvest = search.get_people()

        # Combine lists and strip out duplicate findings for unique lists
        all_emails = google_harvest + bing_harvest + yahoo_harvest
        all_people = link_harvest + jigsaw_harvest

        print(green("[+] The search engines returned {} emails, {} names, and {} Twitter \
handles.".format(len(all_emails), len(all_people), len(twit_harvest))))

        # Return the results for emails, people, and Twitter accounts
        return all_emails, all_people, twit_harvest

    def harvest_twitter(self, handle):
        """Function to lookup the provided handle on Twitter using Tweepy."""
        if self.twit_api is None:
            print(yellow("[*] Twitter API access is not setup, so skipping Twitter handle \
lookups."))
        else:
            # Drop the lonely @ Harvester often includes and common false positives
            if handle == '@' or handle == '@-moz-keyframes' or \
                handle == '@keyframes' or handle == '@media' or handle == '@broofa.com':
                print(yellow("[*] Skipping dead end Twitter handle, {}".format(handle)))
            else:
                try:
                    print(green("[+] Looking up {} on Twitter".format(handle)))
                    user_data = {}
                    user = self.twit_api.get_user(handle.strip('@'))
                    user_data['real_name'] = user.name
                    user_data['handle'] = user.screen_name
                    user_data['location'] = user.location
                    user_data['followers'] = user.followers_count
                    user_data['user_description'] = user.description

                    return user_data
                except Exception as error:
                    print(red("[!] Error involving {} -- could be an invalid \
account.".format(handle)))
                    print(red("L.. Details: {}".format(error)))

    def harvest_linkedin(self, target, company):
        """Construct a Bing search URL and scrape for LinkedIn profile links related to the
        target's name and company.
        """
        print(green("[+] Looking for potential LinkedIn profiles \
for {} at {}".format(target, company)))
        url = 'http://www.bing.com/search?q=site:linkedin.com%20"{}"%20"{}"'.format(target, company)
        html = requests.get(url)
        soup = BS(html.text, "html.parser")
        result = soup.findAll('li', {'class': 'b_algo'})
        name = target.split(" ")
        refs = []
        for i in result:
            # Get href links from Bing's source
            link = i.a['href']
            if '/dir/' in link or '/title/' in link or 'groupItem' in link or \
                not 'linkedin.com' in link:
                continue
            else:
                if name[0].lower() in link or name[1].lower() in link:
                    refs.append(link)
                    # Take just the first result to avoid large, unmanageable lists
                    break
        # Remove duplicate results
        no_dups = set(refs)

        return no_dups

    def harvest_emailhunter(self, domain):
        """"Call upon EmailHunter's API to collect known email addresses for a domain and other
        information, such as names, job titles, and the original source of the data.

        A free EmailHunter API key is required.
        """
        results = None

        if self.emailhunter_api_key:
            emailhunter_api_url = "https://api.hunter.io/v2/domain-search?\
domain={}&api_key={}".format(domain, self.emailhunter_api_key)
            request = requests.get(emailhunter_api_url)
            results = request.json()

            if "errors" in results:
                print(red("[!] The request to EmailHunter returned an error!"))
                print(red("L.. Details: {}".format(results['errors'])))
                return None

            print(green("[+] Hunter has contact data for {} \
people.".format(len(results['data']['emails']))))

        return results

    def process_harvested_lists(self, harvester_emails, harvester_people,\
    harvester_twitter, hunter_json):
        """Take data harvested from EmailHunter and TheHarvester, combine it, make unique lists,
        and return the total results.
        """
        temp_emails = []
        twitter_handles = []
        job_titles = {}
        linkedin = {}
        phone_nums = {}

        # Process emails found by TheHarvester
        for email in harvester_emails:
            email = email.lower()
            temp_emails.append(email)

        # Process emails and people found by Hunter
        if hunter_json:
            for result in hunter_json['data']['emails']:
                email = result['value'].lower()
                temp_emails.append(email)

                if "first_name" in result and "last_name" in result:
                    if result['first_name'] is not None and result['last_name'] is not None:
                        person = result['first_name'] + " " + result['last_name']
                        harvester_people.append(person)
                        if "position" in result:
                            if result['position'] is not None:
                                job_titles[person] = result['position']
                        if "linkedin" in result:
                            if result['linkedin'] is not None:
                                linkedin[person] = result['linkedin']
                        if "phone_number" in result:
                            if result['phone_number'] is not None:
                                phone_nums[person] = result['phone_number']

                if "twitter" in email:
                    if result['twitter'] is not None:
                        harvester_twitter.append(result['twitter'])

        # Remove any duplicate results
        unique = set(temp_emails)
        unique_emails = list(unique)

        unique = set(harvester_people)
        unique_people = list(unique)

        for twit in harvester_twitter:
            # Split handle from account description and strip rogue periods
            handle = twit.split(' ')[0]
            handle = handle.rstrip('.')
            twitter_handles.append(handle.lower())
        unique = set(twitter_handles)
        unique_twitter = list(unique)

        print(green("[+] Final unique findings: {} emails, {} people, \
{} Twitter handles.".format(len(unique_emails), len(unique_people), len(unique_twitter))))

        return unique_emails, unique_people, unique_twitter, job_titles, linkedin, phone_nums
Ejemplo n.º 46
0
chrome_browser = webdriver.Chrome(chrome_path)

chrome_browser.maximize_window()
"""
Browser Arguments:

–headless

To open browser in headless mode. Works in both Chrome and Firefox browser

–start-maximized

To start browser maximized to screen. Requires only for Chrome browser. Firefox by default starts maximized

–incognito

To open private chrome browser

–disable-notifications

To disable notifications, works Only in Chrome browser
"""
options = Options()
options.add_argument("--headless")
options.add_argument("--start-maximized")
options.add_argument("--disable-notifications")
options.add_argument("--incognito")

driver = webdriver.Chrome(chrome_options=options,
                          executable_path="Path to driver")
Ejemplo n.º 47
0
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#from selenium.webdriver.common.keys import Keys

print os.getcwd()
os.chdir("C:\Users\Ram\Desktop")
print os.getcwd()
log_filename = "example1.log"
logging.basicConfig(filename=log_filename, level=logging.DEBUG)
logging.debug('debug message')
logging.info('info message')
logging.warn('warn message')
logging.error('error message')
logging.critical('critical message')

chrome_options = Options()
#chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("--disable-notificationss")
#chrome_options.add_argument("--incognito")
logging.info("added chrome arguments")
driver = webdriver.Chrome(
    chrome_options=chrome_options,
    executable_path=
    "C:\Users\Ram\PycharmProjects\untitled2\divers\chromedriver.exe")
driver.get("http://www.google.co.in")
logging.debug("opened google search page")
print driver.title
time.sleep(5)

driver.close()
Ejemplo n.º 48
0
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
chrome_options.add_argument(
    '--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'
)
chrome = webdriver.Chrome(options=chrome_options)

chrome.get(
    'https://m.avito.ru/moskva/kommercheskaya_nedvizhimost?cd=1&searchForm=true'
)
# блок авторизации (если это требуется)
# chrome.find_element_by_id("main_login_btn").click()

chrome.find_element_by_class_name("css-1bsvtvg").click()

time.sleep(2)
chrome.find_element_by_class_name("css-7ohp1y").click()
time.sleep(2)

chrome.find_element_by_class_name("css-m66apo").click()

# Дальше должна идти проверка по атрибутам, но моих знаний на данный момент не хватает, чтоб корректно выбрать селекторы кнопок, т.к. не сталкивался с data-marker
# Для работы скрипта нужен Python 3.9 и Selenium webdriver
Ejemplo n.º 49
0
def create_chrome_driver(dl_dir, headless_flg):
    options = Options()
    options.add_argument('--disable-gpu')
    options.add_argument('--disable-extensions')
    options.add_argument('--proxy-server="direct://"')
    options.add_argument('--proxy-bypass-list=*')
    options.add_argument('--start-maximized')

    if headless_flg:
        options.add_argument('--headless')

    driver = webdriver.Chrome(chrome_options=options)
    driver.implicitly_wait(10)

    if headless_flg:
        driver.command_executor._commands["send_command"] = (
            "POST", '/session/$sessionId/chromium/send_command')
        params = {'cmd': 'Page.setDownloadBehavior', 'params': {
            'behavior': 'allow', 'downloadPath': dl_dir}}
        driver.execute("send_command", params)

    return driver
def loginAndFetchTickets(macid):
    try:

        config.logger.info('Logging into ITSM tool for ticket fetching')
        # headless access
        options = Options()
        options.headless = True
        options.add_argument("--window-size=1920,1200")
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')
        #         options.add_argument('--ignore-certificate-errors')
        driver = webdriver.Chrome(
            options=options, executable_path=ChromeDriverManager().install())
        # Gets the URL
        print("Opening browser with ITSM")
        # Gets the URL
        driver.get(
            'https://staging-ci.symphonysummit.com/Afsservicedesk/Summit_WebLogin.aspx'
        )
        print("maxamize window")
        driver.maximize_window()

        time.sleep(3)

        # Finds the user name and password by id from HTML
        element = driver.find_element_by_id("txtLogin")
        element1 = driver.find_element_by_id("txtPassword")

        # Enters the user name and password
        element.send_keys("*****@*****.**")
        element1.send_keys("Afs@123#")
        print("inside itsm")
        # Clicks the login button
        driver.find_element_by_id("butSubmit").click()

        # This is used to check if a duplicate login window pop ups, if it does press continue otherwise pass
        try:
            if driver.find_element_by_class_name(
                    "TitlePanel").text == 'DUPLICATE LOGIN':
                driver.switch_to.frame(
                    driver.find_element_by_tag_name("iframe"))
                driver.find_element_by_id("ContentPanel_btnContinue").click()
            else:
                pass
        except:
            print(" ")

        time.sleep(1)
        driver.find_element_by_id("IM").click()
        driver.find_element_by_id("IM_WORKGROUP_TICKETS").click()

    except Exception as e:

        config.logger.exception(
            'Error in logging into ITSM tool for ticket fetching ' + str(e))

    incd_id = []
    sptm = []
    prv_log = []
    soln = []
    cal = []
    ten = []
    loc = []
    med = []
    src = []
    log_tm = []
    urg = []
    imp = []
    pr = []
    wg = []
    at = []
    sw = []
    rc = []
    emails = []
    # Calculating number of tickets
    num_of_tickets = int(
        driver.find_element_by_xpath(
            '//*[@id="BodyContentPlaceHolder_lblCurrentRange"]').text.split()
        [-1].strip())
    for i in range(1, 2):
        print("fetching ticket", i)
        try:
            config.logger.info(
                'Finding ticket attributes and storing it in a dataframe')
            # This checks if the ticket is new
            if driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_gvMyTickets"]/tbody/tr[' +
                    str(i + 1) + ']/td[4]/h4/span').text == 'New':

                # This stores the incident id
                inc_id = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_gvMyTickets"]/tbody/tr[' +
                    str(i + 1) + ']/td[2]/div[2]/a[1]').text

                #This clicks on the incident id
                driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_gvMyTickets"]/tbody/tr[' +
                    str(i + 1) + ']/td[2]/div[2]/a[1]').click()
                time.sleep(2)

                # This clicks on the assigned
                driver.find_element_by_xpath(
                    '//*[@id="ticketdetail"]/div[2]/div/div[2]/div/div[1]/div/div/ul/li[2]/a'
                ).click()

                # This clicks on the assigned to option
                driver.find_element_by_xpath(
                    '//*[@id="s2id_BodyContentPlaceHolder_ddlAssignedExecutive"]/a/span[2]/b'
                ).click()
                time.sleep(2)
                afs = driver.find_element_by_xpath(
                    '//*[@id="s2id_autogen34_search"]')
                afs.send_keys("AFS Automation", Keys.ENTER)
                #pyautogui.press("down")
                #pyautogui.press("enter")

                # This clicks on  the communication panel
                driver.find_element_by_xpath(
                    '//*[@id="aCommunication"]').click()

                # This fills the communication panel
                text = driver.find_element_by_xpath(
                    '//*[@id="Communication"]/div/div[2]/div[3]/div[2]/div')
                text.send_keys("Ticket is in progress")

                #my comment
                # Clicks on the resolved part
                #driver.find_element_by_xpath('//*[@id="ticketdetail"]/div[2]/div/div[2]/div/div[1]/div/div/ul/li[5]/a').click()

                # Clicks on the general panel
                driver.find_element_by_xpath('//*[@id="general"]/a').click()

                #  # This clicks on the violation panel , if its is yes then it fills the text
                #  if driver.find_element_by_xpath('//*[@id="General"]/div[2]/div/div[2]/div[2]/div/div[2]/label').text[-3:] == 'Yes':
                #      driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
                #      time.sleep(2)
                #      driver.find_element_by_xpath('//*[@id="iRespReasonOpener"]').click()
                #      text1 = driver.find_element_by_xpath('//*[@id="BodyContentPlaceHolder_txtRespViolationReason"]')
                #      text1.send_keys('This happened because i was sleeping')
                #      driver.find_element_by_xpath('//*[@id="divRespViolationReason"]/div[3]/input').click()
                #  else:
                #      pass
                #
                # Clicks on the solution panel and fills it
                # solution = driver.find_element_by_xpath('//*[@id="divSolutionRow"]/div[2]/div/div[2]/div')
                # solution.send_keys("Ticket Resolved")

                # This scrolls the window
                driver.execute_script(
                    "window.scrollTo(0, document.body.scrollHeight);")
                time.sleep(2)
                driver.execute_script(
                    "window.scrollTo(0, document.body.scrollHeight);")

                # This clicks on the resolution code and selects resolved
                #driver.find_element_by_xpath('//*[@id="s2id_BodyContentPlaceHolder_ddlResolutionCode"]/a/span[2]/b').click()
                #pyautogui.press("down")
                #pyautogui.press("enter")

                driver.execute_script(
                    "window.scrollTo(0, document.body.scrollHeight);")
                time.sleep(2)

                # This fills the asset details
                asset_id = driver.find_element_by_xpath('//*[@id="txt_26"]')
                asset_id.send_keys("Asset_id")

                # This fills the Serial Number
                serial_no = driver.find_element_by_xpath('//*[@id="txt_25"]')
                serial_no.send_keys("Serial_no")

                time.sleep(5)

                # This clicks on the violation panel , if its is yes then it fills the text
                if driver.find_element_by_xpath(
                        '//*[@id="General"]/div[2]/div/div[2]/div[2]/div/div[2]/label'
                ).text[-3:] == 'Yes':
                    driver.execute_script(
                        "window.scrollTo(0, document.body.scrollHeight);")
                    time.sleep(2)
                    driver.find_element_by_xpath(
                        '//*[@id="iRespReasonOpener"]').click()
                    text1 = driver.find_element_by_xpath(
                        '//*[@id="BodyContentPlaceHolder_txtRespViolationReason"]'
                    )
                    text1.send_keys('This happened because of system latency')
                    driver.find_element_by_xpath(
                        '//*[@id="divRespViolationReason"]/div[3]/input'
                    ).click()
                else:
                    pass

                # This appends the incident id
                incd_id.append(inc_id)

                # This stores the symptoms and appends
                symptom = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_lblSymptomDisplay"]').text
                sptm.append(symptom)

                #This stores the private log
                driver.find_element_by_xpath(
                    '//*[@id="aCommunication"]').click()
                private_logg = driver.find_element_by_xpath(
                    '//*[@id="Communication"]/div/div[2]/div[3]/div[2]/div'
                ).text
                prv_log.append(private_logg)

                # This stores the solution
                driver.find_element_by_xpath('//*[@id="general"]/a').click()
                sol = driver.find_element_by_xpath(
                    '//*[@id="divSolutionRow"]/div[2]/div/div[2]/div').text
                soln.append(sol)

                #Caller
                caller = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_ucUserInformation_lblName"]'
                ).text
                cal.append(caller)

                #Tenant
                tenant = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_ucUserInformation_lblCustomer"]'
                ).text
                ten.append(tenant)

                #Email

                email = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_ucUserInformation_lblEmail"]/a'
                ).text
                emails.append(email)

                # Location
                location = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_ucUserInformation_lblLocation"]'
                ).text
                loc.append(location)

                # Medium
                medium = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_lblMediumDisplay"]').text
                med.append(medium)

                # Source
                source = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_lblSourceDisplay"]').text
                src.append(source)

                # Logged Time
                logg_time = driver.find_element_by_xpath(
                    '//*[@id="BodyContentPlaceHolder_lblLogTime"]').text
                log_tm.append(logg_time)

                # Urgency
                urgency = driver.find_element_by_id(
                    's2id_BodyContentPlaceHolder_ddlUrgency').text
                urg.append(urgency)

                # Impact
                impact = driver.find_element_by_xpath(
                    '//*[@id="s2id_BodyContentPlaceHolder_ddlImpact"]/a').text
                imp.append(impact)

                # Priority
                priority = driver.find_element_by_id(
                    's2id_BodyContentPlaceHolder_ddlPriority').text
                pr.append(priority)

                # Workgroup
                wrk_gp = driver.find_element_by_id(
                    's2id_BodyContentPlaceHolder_ddlWorkgroup').text
                wg.append(wrk_gp)

                # Assigned to
                assg_to = driver.find_element_by_id(
                    's2id_BodyContentPlaceHolder_ddlAssignedExecutive').text
                at.append(assg_to)

                #Service window
                serv_win = driver.find_element_by_id(
                    's2id_BodyContentPlaceHolder_ddlSLA').text
                sw.append(serv_win)

                # Resolution code
                resol_code = driver.find_element_by_id(
                    's2id_BodyContentPlaceHolder_ddlResolutionCode').text
                rc.append(resol_code)

                driver.execute_script(
                    "window.scrollTo(0, document.body.scrollHeight);")
                time.sleep(2)

                #This clicks on the submit button
                #driver.find_element_by_xpath('//*[@id="BodyContentPlaceHolder_btnSave"]').click()
                #time.sleep(10)

                #This clicks on the final ok button
                #driver.current_window_handle
                #driver.find_element_by_xpath('/html/body/div[9]/div/div/div[2]/button').click()

                time.sleep(5)

                driver.find_element_by_id("IM").click()
                driver.find_element_by_id("IM_WORKGROUP_TICKETS").click()

            else:
                continue

        except Exception as e:

            config.logger.exception(
                'Error in storing attributes of a ticket ' + str(e))

    config.logger.info('Storing values in a dataframe')
    df_dict ={'Incident ID':incd_id, 'Description':sptm ,'Private Log':prv_log ,'Caller':cal,'Tenant':ten,\
                  'User_Mail':emails,'Location':loc,'Medium':med,'Source':src,'Logged Time':log_tm,'Urgency':urg,'Impact':imp,'Priority':pr,\
                  'Work Group':wg,'Assigned To':at,'Service Window':sw,'MAC_ID':macid}#,'Resolution Code':rc,'Solution':soln,}
    df = pd.DataFrame(df_dict, index=None)

    print('df unsorted is', df)
    #df.sort_values(by='Incident ID',inplace=True)
    #     df.to_csv('Incidents_no_pred.csv')
    print('df sorted is', df)

    #     df.to_excel('Incidents.xlsx',sheet_name='All_Incidents')

    config.logger.info(
        'Calling the prediction script for ticket classification')
    df = predicting_part.predictionsOnEachTicket(df)
    df.sort_values(by='Incident ID', inplace=True)

    driver.find_element_by_xpath('//*[@id="imgProfile"]').click()
    driver.find_element_by_xpath('//*[@id="hrefLogout"]').click()
    driver.quit()
    print("logged out")
    #threading.Timer(180, loginAndFetchTickets).start()

    return df, num_of_tickets
Ejemplo n.º 51
0
# --------------------------------------------------------------------------------

# getting articles purportedly on kindle cloud library (kept track of locally)

kindle_urls = []
with open("/Users/dpham/Development/Applications/article-sender/kindle_urls.txt", "r") as f:
    for line in f:
        kindle_urls.append(line.strip())

print(kindle_urls)
print(rl_urls)

# --------------------------------------------------------------------------------

# sending new articles to kindle
options = Options()
options.headless = True
browser = webdriver.Chrome(options=options)

base_url = "https://pushtokindle.fivefilters.org/send.php?src=safari-app&url="
browser.get(base_url + "https://google.com")
time.sleep(2)
browser.find_element_by_xpath(r'//*[@id="contentIdForA11y3"]/div/div[4]/div/input').send_keys("<receiving email>")
time.sleep(2)
browser.find_element_by_xpath(r'//*[@id="contentIdForA11y3"]/div/div[5]/div/input').send_keys("<sending email>")

for url in rl_urls:
    if url not in kindle_urls:
        with open("/Users/dpham/Development/Applications/article-sender/kindle_urls.txt", "a") as f:
            f.write(url + "\n")
        print(url)
Ejemplo n.º 52
0
from urllib.request import urlopen, Request
from bs4 import BeautifulSoup
import re

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

reg_url = "https://etherscan.io/token/0xaf9f549774ecedbd0966c52f250acc548d3f36e5?a=0xe8f063c4dc60b2f6c2c900d870ddcdae7daab7f6"

options = Options()
options.add_argument("start-maximized")
options.add_argument('--no-sandbox')
options.add_argument("--hide-scrollbars")
options.add_argument("disable-infobars")
options.add_argument('--disable-dev-shm-usage')
# options.add_argument("window-size=1920,1080")
# options.headless = True
# options.add_argument('--headless') # can't be headless or would lead to error

driver = webdriver.Chrome(options=options)
# driver.set_window_size(1200, 600)
driver.get(reg_url)

wait = WebDriverWait(driver, 10)
# frame = wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tokentxnsiframe")))
Ejemplo n.º 53
0
# import packages
import re
import bs4
from bs4 import BeautifulSoup
import requests
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument('--no-sandbox')
options.add_argument("--disable-extensions")
options.add_argument('--log-level=3')

# Create new Instance of Chrome in incognito mode
browser = webdriver.Chrome(
    executable_path=
    r'/Users/matt/Documents/STUFF/random other shit/chromedriver.exe',
    chrome_options=options)


# get soup object
def get_soup(text):
    return BeautifulSoup(text, "lxml")
Ejemplo n.º 54
0
        date = info.find(class_='so-icon time').text.strip()
        up = info.find(class_='up-name').string.strip()
        print(f'爬取: {title} up主: {up} 观看次数: {views}')
        global n
        sheet.write(n, 0, title)
        sheet.write(n, 1, desc)
        sheet.write(n, 2, views)
        sheet.write(n, 3, barrages)
        sheet.write(n, 4, date)
        sheet.write(n, 5, up)
        sheet.write(n, 6, href)
        n += 1


if __name__ == '__main__':
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    browser = webdriver.Chrome(options=options)  # 设置无界面爬虫
    browser.set_window_size(1400, 900)  # 设置全屏,注意把窗口设置太小的话可能导致有些button无法点击

    n = 1
    excel = xlwt.Workbook(encoding='utf-8', style_compression=0)
    sheet = excel.add_sheet('爱乐之城b站视频信息', cell_overwrite_ok=True)
    sheet.write(0, 0, '标题')
    sheet.write(0, 1, '描述')
    sheet.write(0, 2, '观看次数')
    sheet.write(0, 3, '弹幕数量')
    sheet.write(0, 4, '上传时间')
    sheet.write(0, 5, 'up主')
    sheet.write(0, 6, '视频链接')
Ejemplo n.º 55
0
def main():

    url = "https://www.fhi.no/sv/vaksine/koronavaksinasjonsprogrammet/koronavaksinasjonsstatistikk/"

    # Options for Chrome WebDriver
    op = Options()
    op.add_argument("--disable-notifications")
    op.add_experimental_option(
        "prefs", {
            "download.prompt_for_download": False,
            "download.directory_upgrade": True,
            "safebrowsing.enabled": True
        })

    with webdriver.Chrome(options=op) as driver:

        # Setting Chrome to trust downloads
        driver.command_executor._commands["send_command"] = (
            "POST", "/session/$sessionId/chromium/send_command")
        params = {
            "cmd": "Page.setDownloadBehavior",
            "params": {
                "behavior": "allow",
                "downloadPath": "automations"
            }
        }
        command_result = driver.execute("send_command", params)

        driver.get(url)
        time.sleep(1)
        driver.execute_script("window.scrollTo(0, 750)")
        driver.find_element_by_class_name("highcharts-exporting-group").click()

        for item in driver.find_elements_by_class_name("highcharts-menu-item"):
            if item.text == "Last ned CSV":
                item.click()
                time.sleep(2)
                break

    df = pd.read_csv(
        "automations/antall-personer-vaksiner.csv",
        sep=";",
        usecols=["Category", "Totalt personer vaksinert med 1. dose"])

    df = df.rename(
        columns={
            "Totalt personer vaksinert med 1. dose": "total_vaccinations"
        })

    if "Category" in df.columns:
        df = df.rename(columns={"Category": "date"})
        df["date"] = pd.to_datetime(df["date"], format="%d.%m.%Y")
    elif "DateTime" in df.columns:
        df = df.rename(columns={"DateTime": "date"})
        df["date"] = pd.to_datetime(df["date"], format="%Y-%m-%d")

    df = df.groupby("total_vaccinations", as_index=False).min()

    df.loc[:, "location"] = "Norway"
    df.loc[:, "vaccine"] = "Pfizer/BioNTech"
    df.loc[:, "source_url"] = url

    df.to_csv("automations/output/Norway.csv", index=False)

    os.remove("automations/antall-personer-vaksiner.csv")
Ejemplo n.º 56
0
 def __init__(self):
     chrome_options = Options()
     chrome_options.add_argument('--headless')
     self.driver = webdriver.Chrome(chrome_options=chrome_options)
url = str(custom_data[0].split(" : ")[1])
save_dir = str(custom_data[1].split(" : ")[1])
file_type = custom_data[2].split(" : ")[1].split(" ")
username = str(custom_data[3].split(" : ")[1])
password = str(custom_data[4].split(" : ")[1])
down_count = custom_data[5].split(" : ")[1]

# print (url)

# page_response = requests.get(url, timeout=5)
# page_content = BeautifulSoup(page_response.content, "html.parser")
# divs = page_content.find_all("div", class_="tjGalleryItem")
# print(page_content)

options = Options()
# options.add_argument("--headless")
# options.add_argument("download.default_directory=" + save_dir + "images")
driver = webdriver.Chrome(options=options)
# driver = webdriver.Chrome()
driver.get("https://www.iclipart.com/")

driver.find_element_by_xpath(
    '/html/body/table/tbody/tr[1]/td/table/tbody/tr/td/table[1]/tbody/tr/td/ul/li[5]'
).click()
driver.find_element_by_xpath('//*[@id="frmLogin"]/div[2]/div[2]/input').clear()
driver.find_element_by_xpath(
    '//*[@id="frmLogin"]/div[2]/div[2]/input').send_keys(username)
driver.find_element_by_xpath('//*[@id="frmLogin"]/div[3]/div[2]/input').clear()
driver.find_element_by_xpath(
    '//*[@id="frmLogin"]/div[3]/div[2]/input').send_keys(password)
Ejemplo n.º 58
0
async def carbon_api(e):
    cat = await edit_or_reply(e, "`Processing....`")
    CARBON = "https://carbon.now.sh/?l={lang}&code={code}"
    textx = await e.get_reply_message()
    pcode = e.text
    if pcode[5:]:
        pcodee = str(pcode[5:])
        if "|" in pcodee:
            pcode, skeme = pcodee.split("|")
        else:
            pcode = pcodee
            skeme = None
    elif textx:
        pcode = str(textx.message)
        skeme = None  # Importing message to module
    pcode = deEmojify(pcode)
    code = quote_plus(pcode)  # Converting to urlencoded
    await cat.edit("`Meking Carbon...`\n`25%`")
    url = CARBON.format(code=code, lang=CARBONLANG)
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.binary_location = Config.CHROME_BIN
    chrome_options.add_argument("--window-size=1920x1080")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-gpu")
    prefs = {"download.default_directory": "./"}
    chrome_options.add_experimental_option("prefs", prefs)
    driver = webdriver.Chrome(executable_path=Config.CHROME_DRIVER,
                              options=chrome_options)
    driver.get(url)
    await cat.edit("`Be Patient...\n50%`")
    download_path = "./"
    driver.command_executor._commands["send_command"] = (
        "POST",
        "/session/$sessionId/chromium/send_command",
    )
    params = {
        "cmd": "Page.setDownloadBehavior",
        "params": {
            "behavior": "allow",
            "downloadPath": download_path
        },
    }
    driver.execute("send_command", params)
    driver.find_element_by_xpath(
        "/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]"
    ).click()
    if skeme is not None:
        k_skeme = driver.find_element_by_xpath(
            "/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input"
        )
        k_skeme.send_keys(skeme)
        k_skeme.send_keys(Keys.DOWN)
        k_skeme.send_keys(Keys.ENTER)
    else:
        color_scheme = str(random.randint(1, 29))
        driver.find_element_by_id(("downshift-0-item-" + color_scheme)).click()
    driver.find_element_by_id("export-menu").click()
    driver.find_element_by_xpath("//button[contains(text(),'4x')]").click()
    driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click()
    await cat.edit("`Processing..\n75%`")
    # Waiting for downloading
    await asyncio.sleep(2.5)
    color_name = driver.find_element_by_xpath(
        "/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input"
    ).get_attribute("value")
    await cat.edit("`Done Dana Done...\n100%`")
    file = "./carbon.png"
    await cat.edit("`Uploading..`")
    await e.client.send_file(
        e.chat_id,
        file,
        caption="`Here's your carbon!` \n**Colour Scheme: **`{}`".format(
            color_name),
        force_document=True,
        reply_to=e.message.reply_to_msg_id,
    )
    os.remove("./carbon.png")
    driver.quit()
    await cat.delete()
Ejemplo n.º 59
0
    def __init__(self, _base_driver=None):
        _config = self.get_config()
        try:
            using_headless = os.environ["using_headless"]
        except KeyError:
            using_headless = None
            print('没有配置环境变量 using_headless, 按照有界面方式运行自动化测试')
        _chrome_options = Options()
        if using_headless is not None and using_headless.lower() == 'true':
            print('使用无界面方式运行')
            _chrome_options.add_argument("--headless")
            _chrome_options.add_argument("--disable-extensions")
            _chrome_options.add_argument("--display-gpu")
            _chrome_options.add_argument("--no-sandbox")
        _base_driver: WebDriver
        if _base_driver is None:

            _chrome_options.add_experimental_option("w3c", False)
            self._driver = webdriver.Chrome(executable_path=_config.get(
                'driver', 'chrome_driver'),
                                            options=_chrome_options)
            self._driver.maximize_window()
            self._driver.implicitly_wait(4)
            # self._get_cookies_sanxiaod()
            self._cookie_login()
        else:
            self._driver = _base_driver
Ejemplo n.º 60
-1
    def setUp(self):

        chromium_path = '/usr/bin/chromium'
        chromedriver_path = './chromedriver'
        
        opts = Options()
        opts.binary_location = chromium_path
        opts.add_experimental_option("prefs", {
            "download.default_directory": "./test_downloaded", 
            "helperApps.neverAsk.saveToDisk": "octet/stream", 
            "directory_upgrade": True,
            "profile": {"default_content_settings": {"multiple-automatic-downloads": 1}}
            })
        
        self.driver = webdriver.Chrome(chrome_options=opts, executable_path=chromedriver_path)

        #self.driver = webdriver.Firefox()        
        url = os.getenv('TEST_URL', config.url)
        self.driver.get(url)

        self.__load_pages()

        # Sets up by redirecting to login page
        main_page = page.MainPage(self.driver)
        main_page.click_login_link()