Ejemplo n.º 1
0
def load_stockweb(stock_sn, datepath):
    nowget = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    #stock_sn="3231"
    #weblink = "http://traderoom.cnyes.com/tse/quote2FB.aspx?code="+stock_sn
    weblink = "https://stock.pchome.com.tw/stock/sto0/ock3/sid" + stock_sn + ".html"

    #r = requests.get(weblink,timeout=10)
    #r.encoding = "utf-8"
    #soup = BeautifulSoup(r.text, "lxml")

    webdriver.implicitly_wait(10)
    webdriver.get(weblink)
    print(webdriver.title)
    soup = BeautifulSoup(webdriver.page_source, "lxml")
    #fp = open("index.html", "w", encoding="utf8")
    #fp.write(soup.prettify())
    #print("寫入檔案index.html...")
    #fp.close()
    #webdriver.quit()

    os.chdir("\\py3_prj\\pyweb\\stock_data\\" + datepath)
    sfilename = "stock" + stock_sn + "d" + nowget[0:10] + ".html"
    fp = open(sfilename, "w", encoding="utf8")
    fp.write(soup.prettify())

    #print(nowget[0:10])
    print("寫入檔案" + sfilename)
    fp.close()
Ejemplo n.º 2
0
def login(webdriver):
    webdriver.get(url)
    webdriver.implicitly_wait(10)
    webdriver.switch_to.frame(webdriver.find_element_by_tag_name('iframe'))
    webdriver.find_element_by_id('username').send_keys(USERNAME)
    webdriver.find_element_by_id('password').send_keys(PASSWORD)
    webdriver.find_element_by_xpath("//input[@type='image']").click()
    webdriver.implicitly_wait(5)
Ejemplo n.º 3
0
def get_browserstack_webdriver(capabilities):
    capabilities.setdefault("resolution", "1920x1080")
    capabilities.setdefault("browserstack.local", True)
    capabilities.setdefault("browserstack.debug", True)

    config = os.path.expanduser("~/.browserstack.json")
    cfg = json.load(open(config))

    hub = "http://{user}:{key}@hub.browserstack.com/wd/hub"
    hub = hub.format(**cfg)
    webdriver = selenium.webdriver.Remote(command_executor=hub, desired_capabilities=capabilities)

    webdriver.set_page_load_timeout(60)
    webdriver.implicitly_wait(10)
    return webdriver
def get_browserstack_webdriver(capabilities):
    capabilities.setdefault('resolution', '1920x1080')
    capabilities.setdefault('browserstack.local', True)
    capabilities.setdefault('browserstack.debug', True)

    config = os.path.expanduser('~/.browserstack.json')
    cfg = json.load(open(config))

    hub = 'http://{user}:{key}@hub.browserstack.com/wd/hub'
    hub = hub.format(**cfg)
    webdriver = selenium.webdriver.Remote(command_executor=hub,
                                          desired_capabilities=capabilities)

    webdriver.set_page_load_timeout(60)
    webdriver.implicitly_wait(10)
    return webdriver
Ejemplo n.º 5
0
def get_results_by_year(webdriver, input_file):
    login(webdriver)
    response_files_by_year = {}
    submenus = [
        submenu.get_attribute('id')
        for submenu in webdriver.find_elements_by_xpath(
            "//div[@id='menugroup_4']/div[not(@id='menugroup_4_1')]")
    ]
    for submenu_id in submenus:
        year = send_request_file(webdriver, submenu_id, input_file)
        time.sleep(10)
        file = download_response_file(webdriver)
        if (file):
            response_files_by_year[year] = file
        webdriver.implicitly_wait(2)
    time.sleep(3)
    webdriver.quit()
    return response_files_by_year
Ejemplo n.º 6
0
def search_track(webdriver, search):
    """
    Searchs for a particular track in slider
    website and returns the results table.

    Parameters:
    ----------
    webdriver : selenium.webdriver
    search : str
        track name to search

    Returns:
    --------
    selenium.webdriver.firefox.webelement.FirefoxWebElement
    """
    webdriver.get('https://slider.kz')
    search_form = webdriver.find_element_by_xpath(
        '//*[@id="buttonSearch"]/input')
    search_form.send_keys(search)
    search_form.send_keys(Keys.RETURN)
    results = webdriver.find_element_by_xpath('//*[@id="liveaudio"]')
    webdriver.implicitly_wait(5)
    return results
def getMatchLinks(webdriver):
    # find the button for next pagination
    next_button = webdriver.find_element_by_xpath(
        "//*[@id='tie-block_2186']/div/div[1]/div/div/ul/li[2]/a")
    # results = driver.find_elements_by_xpath("//li/h3/a")
    # print('cantidad de resultados: {}'.format(len(results)))
    partidos = []
    loop = True
    cont = 1

    # loop the results
    while loop:
        wait = WebDriverWait(webdriver, 10)
        next_button = wait.until(
            EC.element_to_be_clickable((By.CLASS_NAME, 'next-posts')))

        # next_button = driver.find_element_by_class_name('next-posts')
        loop = not ('pagination-disabled' in next_button.get_attribute('class'))
        #print(next_button.get_attribute('class') + ' | ' + str(loop))

        results = webdriver.find_elements_by_xpath("//li/h3/a")
        print(' {} results in page {} !'.format(str(len(results)), cont))

        for result in results:
            partido = Game(result.text, result.get_attribute('href'))
            partidos.append(partido)

        if loop:
            next_button.click()
            # wait for the transition animation to finish loading results
            time.sleep(6)
            webdriver.implicitly_wait(6)

        cont += 1

    return partidos
Ejemplo n.º 8
0
        Return a list of all fields error messages
        :return: a list of text
        '''
        logger.info('Get error messages displayed on fields')
        self.wait_UI(self.__field_error_loc)
        field_errors = self.find_elements(*self.__field_error_loc)
        error_messages = []
        for error in field_errors:
            error_messages.append(error.text)
        return error_messages


if __name__ == '__main__':
    webdriver = webdriver.Firefox()
    webdriver.maximize_window()
    webdriver.implicitly_wait(10)
    login_page = LoginPage(webdriver)
    login_page.login()
    menu_bar = MenuBar(webdriver)
    menu_bar.wait_UI(menu_bar.menu_button_loc)
    menu_bar.action_toggle_menu()
    time.sleep(1)
    menu_bar.action_expand_app_group('Supply Chain Advantage')
    menu_bar.action_expand_menu('Advantage Dashboard')
    menu_bar.action_expand_menu('searchTest', False, 'search test')
    searchPage = SearchPage(webdriver)
    print(searchPage.get_page_title())
    time.sleep(1)
    print(searchPage.get_all_labels_name(1))
    searchPage.action_searchlike_input('searchLike', 'abc', 2, 'Exactly')
    searchPage.action_listbox_select('ListBox', 'Warehouse 02', 2)
Ejemplo n.º 9
0
from selenium.webdriver.support import expected_conditions as EC
import time
import math

link = "http://suninjuly.github.io/explicit_wait2.html"


def calc(x):
    return str(math.log(abs(12 * math.sin(int(x)))))


try:
    webdriver = webdriver.Chrome()
    webdriver.get(link)
    #wait 5 sec for each element
    webdriver.implicitly_wait(5)
    #WebDriverWait и expected_conditions)
    price = WebDriverWait(webdriver, 12).until(
        EC.text_to_be_present_in_element((By.ID, "price"), "$100"))
    book = webdriver.find_element_by_id("book")
    book.click()

    x = webdriver.find_element_by_id("input_value").text
    y = calc(x)

    input_field = webdriver.find_element_by_id('answer').send_keys(y)

    submit = webdriver.find_element_by_id('solve').click()

finally:
    time.sleep(5)
Ejemplo n.º 10
0
if (uname == None or pwd == None):
    print(
        '===>Failed! Create a file named .env if not already, and enter your login credentials in id and pass variables. Read the setup instructions for details'
    )
    print('===>Exiting...')
    exit()

# else

print('===>Opening Browser')
# uncomment below line if you want to use chrome instead of firefox
# webdriver = webdriver.Chrome(executable_path=chromedriver_path)
webdriver = webdriver.Firefox()
webdriver.implicitly_wait(
    15
)  #will wait until the element appears: for all the elements we find below in the file
sleep(1)

print('===>Opening Instagram')
webdriver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
sleep(2)

print('===>Entering login details')
username = webdriver.find_element_by_name('username')
username.send_keys(uname)
sleep(1)

password = webdriver.find_element_by_name('password')
password.send_keys(pwd)
sleep(1)
Ejemplo n.º 11
0
def setUpBrowser(browser, webdriver):
    print("Run " + browser + " start at: " + str(datetime.datetime.now()))
    print("Chrome envirerment set up")
    print("-------------------------------------")
    webdriver.implicitly_wait(20)
    webdriver.maximize_window()
f = open("/home/dhl/shipment_numbers.csv")

wait = WebDriverWait(webdriver, 60 * 60)

for line in f:
	#Searching for shipment code
	webdriver.find_element_by_id('shipmentCode').send_keys(line)
	webdriver.find_element_by_id('timeIntervall').send_keys('12')
	webdriver.find_element_by_name('search_ta').click()
	#Downloading pdf
	try:
	    actionSelection = wait.until(EC.element_to_be_clickable((By.ID,'pageActionSelect')))
	finally:
		pass
	actionSelection.send_keys('download')
	webdriver.execute_script('javascript:openLayerSelection(\'pieceList\',\'false\')')
	#webdriver.find_element_by_id('signchk').click()
	try:
	    element = wait.until(EC.element_to_be_clickable((By.ID,'signchk')))
	finally:
		pass
	element.click()
	webdriver.find_element_by_xpath("//input[@value='Download']").click()

	webdriver.implicitly_wait(600)
	webdriver.find_element_by_name('cancel_ta').click()
	print "downloaded shipment pdf with shipment code :" + line
   
f.close()
Ejemplo n.º 13
0
def exchange_walutomat(username, password, transaction_type, first_currency, second_currency, amount, rate):
    webdriver.implicitly_wait(10)
    webdriver.get('https://panel.walutomat.pl/moj-walutomat')
    webdriver.find_element_by_id('username').send_keys(username)
    webdriver.find_element_by_id('password').send_keys(password)
    webdriver.find_element_by_class_name('bem-button__inner-text').click()
    time.sleep(5)
    webdriver.get('https://user.walutomat.pl/#/order-placement')
    element = webdriver.find_element_by_id('order-volume')
    element.clear()
    element.send_keys(str(amount))     #send amount
    time.sleep(3)


    #TODO: choose transaction type from a dropdown menu. Buy is by default.
    '''            
    webdriver.find_element_by_id('order-type').click()       #click on buy/sell
    time.sleep(2)
    
    # element from a dropdown menu is wrongly selected. To be fixed 
    if transaction_type == 'buy':       #choose buy/sell
        webdriver.find_element_by_class_name('select2-results__option select2-results__option--highlighted')
    elif transaction_type == 'sell':
        webdriver.find_element_by_link_text('Chcę sprzedać')
    '''

    #TODO: find a way to select element for a different currencies. USD/PLN is by default.
    # element selector from a dropdown menu doesn't work
    '''
    element.send_keys(Keys.TAB, Keys.SPACE)      #click to choose first currency
    time.sleep(2)
    webdriver.find_element_by_class_name('icon-{}'.format(first_currency)).click()        #choose first currency
    time.sleep(2)
    webdriver.send_keys(Keys.TAB)      #click on second currency
    time.sleep(2)
    webdriver.send_keys(Keys.SPACE)
    webdriver.find_element_by_class_name('icon-{}'.format(second_currency)).click()     #choose second currency
    time.sleep(2)
    webdriver.find_element_by_id('price-type-fixed').click()       #choose custom exchange rate
    time.sleep(2)
    '''

    webdriver.find_element_by_id('order-at-price').send_keys(str(rate))     #send custom exchange rate
    time.sleep(3)
    webdriver.find_element_by_id('order-preliminary-submit').click()        #confirm transaction parameters
    time.sleep(3)
    element = webdriver.find_elements_by_class_name('content')
    podsumowanie = element[3].text.split('\n')
    podsumowanie = '{}, kurs {} {}\n{}\n'.format(' '.join(podsumowanie[1:3]), podsumowanie[4].lower(), podsumowanie[5], ' '.join(podsumowanie[6:8]))
    print(podsumowanie)
    confirmation = input('Czy potwierdzasz?')
    if confirmation in ['T', 't', 'Tak', 'tak', 'Y', 'y', 'Yes', 'yes']:
        try:
            webdriver.find_element_by_id('confirm-exchange').click()
            print('Zlecenie zostało złożone.')
        except:
            'Something goes wrong. Laaambaada!'
    else:
        print('Operacja anulowana.')
    webdriver.close()
    return
Ejemplo n.º 14
0
def story_from_followers():
    num = 0
    for user in userlist.users:
        sleep(2)
        webdriver.get('https://www.instagram.com/' + userlist.users[num] + '/')
        sleep(5)
        print("Getting followers with Stories to watch from: {}".format(
            userlist.users[num]))
        num += 1
        sleep(1)
        followers_list__open = webdriver.find_element_by_xpath(
            '/html/body/div[1]/section/main/div/header/section/ul/li[2]/a')
        followers_list__open.click()
        sleep(2)

        fBody = webdriver.find_element_by_xpath("//div[@class='isgrP']")
        scroll = 0
        while scroll < limits.scroll_amount:  # scroll 5 times
            webdriver.execute_script(
                'arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;',
                fBody)
            sleep(2)
            scroll += 1

        fList = webdriver.find_elements_by_xpath("//div[@class='isgrP']//li")

        wbList = webdriver.find_elements_by_xpath(
            "//div[@class='RR-M- h5uC0 SAvC5']")
        print("Users found with Story to watch: {}".format(len(wbList)))
        story_watching_done = 'false'
        stories_next_watch = "true"
        story_watching_counter = 0
        stories_bf_watched = 1

        try:
            for user_story in wbList:
                while story_watching_done == 'false':
                    stories_next_watch = "true"
                    wbList = webdriver.find_elements_by_xpath(
                        "//div[@class='RR-M- h5uC0 SAvC5']")
                    webdriver.execute_script("arguments[0].scrollIntoView();",
                                             wbList[story_watching_counter])
                    wbList[story_watching_counter].click()
                    while stories_next_watch == "true":
                        try:
                            sleep(randint(2, 3))
                            webdriver.implicitly_wait(2)
                            watch_all_stories_next = webdriver.find_element_by_css_selector(
                                ".ow3u_").click()
                            stories_bf_watched += 1
                            print("Stories watched from followers: {}".format(
                                stories_bf_watched))
                        except (NoSuchElementException,
                                StaleElementReferenceException) as e:
                            stories_next_watch = "false"

                    else:
                        try:
                            watch_all_stories_close_from_followers = webdriver.find_element_by_xpath(
                                "/html/body/div[1]/section/div/div/section/div[2]/button[3]/div"
                            )
                            watch_all_stories_close_from_followers.click()
                        except NoSuchElementException:
                            pass
                        wbList = webdriver.find_elements_by_xpath(
                            "//div[@class='RR-M- h5uC0 SAvC5']")
                        story_watching_counter += 1
                        sleep(1)
                else:
                    pass
        except IndexError as error:
            print("Index Error..")
            print("Moving to next user...")
            pass
    else:
        pass