Пример #1
0
def test_MoabWetSlab():
    driver = Chrome(
        '/Users/andymckerrow/Helio/QAPoint/UAC_Python_selenium/_drivers/chromedriver'
    )
    driver.get('https://utahavalanchecenter.org')
    #driver.find_element_by_css_selector('[class*="sm-col sm-col-4 md-col-4 lg-col-4"]').click()
    driver.find_element_by_partial_link_text('Moab').click
    driver.find_element_by_xpath('//div/h5')
Пример #2
0
def test_MoabWindDriftedSnow():
    driver = Chrome(
        '/Users/andymckerrow/Helio/QAPoint/UAC_Python_selenium/_drivers/chromedriver'
    )
    driver.get('https://utahavalanchecenter.org')
    driver.find_element_by_partial_link_text('Moab').click
    driver.find_element_by_xpath('//h5')
    #driver.find_element_by_css_selector('.html5-video-player')
    if ("Wind Drifted Snow" in 'forecast/moab'): pass
Пример #3
0
def insta_details(urls):
    """Take a post url and return post details"""
    browser = Chrome()
    post_details = []
    for link in urls:
        browser.get(link)
        try:
            # This captures the standard like count.
            likes = browser.find_element_by_partial_link_text(' likes').text
        except:
            # This captures the like count for videos which is stored
            xpath_view = '''//*[@id="react-root"]/section/main/div/
                            div/article/div[2]/section[2]/div/span/span'''
            likes = browser.find_element_by_xpath(xpath_view).text
        age = browser.find_element_by_css_selector('a time').text
        try:
            xpath_comment = '''//*[@id="react-root"]/section/main/div/
                               div/article/div[2]/div[1]/ul/li[1]/div/
                               div/div[2]/span'''
            comment = browser.find_element_by_xpath(xpath_comment).text
            insta_link = link.replace('https://www.instagram.com/p', '')
            username_path = '''//*[@id="react-root"]/section/main/div/div/
                               article/header/div[2]/div[1]/div[1]/h2/a'''
            username = browser.find_element_by_xpath(username_path).text
            post_details.append({
                'user': username,
                'link': insta_link,
                'likes/views': likes,
                'age': age,
                'comment': comment
            })
        except:
            continue
        time.sleep(10)
    return post_details
Пример #4
0
class TestLocat():
    def setup_class(self):
        self.driver = Chrome()
        self.driver.implicitly_wait(3)

    def setup(self):
        self.driver.get("https://www.baidu.com")

    def teardown_class(self):
        self.driver.quit()

    def test_id(self):
        self.driver.find_element(By.ID, "kw").send_keys("百度")
        self.driver.find_element_by_id("su").click()

    def test_name(self):
        self.driver.find_element(By.NAME, "wd").send_keys("百度")

    def test_xpath(self):
        self.driver.find_element(By.XPATH, "//*[@name='wd']").send_keys("百度")
        self.driver.find_element_by_xpath("//*[@id='su']").click()

    def test_tag_name(self):
        # 输入框是input标签,按钮也是,所以这里也会报错
        self.driver.find_element(By.TAG_NAME, "input").send_keys("百度")

    def test_link(self):
        self.driver.find_element(By.LINK_TEXT, "新闻").click()

    def test_plink(self):
        self.driver.find_element_by_partial_link_text("闻").click()

    def test_classname(self):
        # 新闻链接,百度首页左上角的链接文字class name 都是相同的,所以此处会报错
        self.driver.find_element(By.CLASS_NAME,
                                 "mnav c-font-normal c-color-t").click()

    def test_cssselector(self):
        self.driver.find_element(By.CSS_SELECTOR, "#kw").send_keys("百度")
        self.driver.find_element_by_css_selector("#su").click()
Пример #5
0
class TestNavigation(StaticLiveServerTestCase):
    """
        test Navigation from homepage
    """
    def setUp(self):
        self.browser = Chrome()
        self.browser.implicitly_wait(10)

    def tearDown(self):
        self.browser.close()

    def test_bad_address_returns_handler404(self):
        """
            Test bad address is caught by the handler and redirect to error page
        """
        print(inspect.currentframe().f_code.co_name)
        response = self.browser.get('%s%s' % (self.live_server_url, '/test'))
        # message = self.browser.find_element_by_tag_name('h1').text
        self.assertTemplateUsed(response, 'errors/errors.html')

    def test_click_mentions(self):
        """
            Test the click on mentions redirect to mentions page
        """
        print(inspect.currentframe().f_code.co_name)
        self.browser.get(self.live_server_url)
        user_url = self.live_server_url + reverse('home_app:mentions')
        element = self.browser.find_element_by_partial_link_text('mentions')
        actions = ActionChains(self.browser)
        actions.move_to_element(element)
        actions.click(element)
        actions.perform()
        self.assertEquals(self.browser.current_url, user_url)

    def test_click_icon_person_to_user(self):
        """
            Test click on the person image redirect to user page
        """
        print(inspect.currentframe().f_code.co_name)
        self.browser.get(self.live_server_url)
        user_url = self.live_server_url + reverse('user_app:user')
        self.browser.find_element(By.CSS_SELECTOR, ".nav-item img").click()
        self.assertEquals(self.browser.current_url, user_url)
Пример #6
0
from selenium.webdriver import Chrome, PhantomJS
from lxml import etree

import threading
import time
import json
import os
import pyautogui
browser = Chrome('D:\webdriver\chromedriver.exe')
browser.get('https://www.cnblogs.com/hjhsysu/p/5735339.html')
# next = browser.find_element_by_id('green_channel_digg')
next = browser.find_element_by_partial_link_text('更多知识库文章...')
a = next.location
# print(a,type(a))
# {'x': 311, 'y': 3169}
browser.execute_script("window.scrollTo(0,%s)" % a['y'])
print('找到了')

# browser.quit()
Пример #7
0
    data = {
        'keyword': "{} site:{}".format(search['keyword'], Site.HUANQIU),
        'time_range': TimeRange.CUSTOM,
        'start_at': search['start_at'],
        'end_at': search['end_at']
    }
    build = BaiduSearchBuilder.from_data(data)
    search_url = build.get_url()
    news_list = []

    while search_url:
        driver.get(search_url)
        results = driver.find_elements_by_class_name('result')

        try:
            next_page = driver.find_element_by_partial_link_text(u'下一页')
        except:
            next_page = None

        for result in results:
            news_list.append({
                'title':
                result.find_element_by_tag_name('h3').text,
                'link':
                result.find_element_by_tag_name('h3').find_element_by_tag_name(
                    'a').get_attribute('href'),
                'time':
                result.find_element_by_class_name(
                    'newTimeFactor_before_abs').text
            })
Пример #8
0
browser.implicitly_wait(2)

stock_list = pd.read_csv('../data/preprocessed/top_consideration/top_consideration_{0}.csv'.format(today))

sendMessage('Begin get EPS data.')
print('Begin get EPS data.')

for st in stock_list.stock_label:
    try:
        print('Open webpage for {0}'.format(st))
        # open web page
        browser.get('https://www.indopremier.com/ipotmember/newsSmartSearch.php?code={0}'.format(st))
        print('Click fundamental menu for {0}'.format(st))

        # click menu fundamental
        browser.find_element_by_partial_link_text('fundamental').click()
        print('Select annual data for {0}'.format(st))
        time.sleep(5)
        # select annual data
        select = Select(browser.find_element_by_id('quarterFundamental'))
        select.select_by_value('4')
        # select.select_by_visible_text('12 Month')
        time.sleep(1)

        print('Click GO for {0}'.format(st))
        # click GO
        browser.find_element_by_xpath("//button[@class='btn btn-default btn-xs-input']").click()
        time.sleep(5)
        print('Get all data for {0}'.format(st))
        # get all data
        all_data = browser.find_element_by_id('popInfoContent').text.split('\n')
Пример #9
0
from selenium.webdriver import Chrome
import requests
import time
url = 'https://accounts.google.com/ServiceLogin/identifier?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26hl%3Dzh-TW%26next%3D%252F&hl=zh-TW&service=youtube&flowName=GlifWebSignIn&flowEntry=AddSession'

driver = Chrome('./chromedriver')

driver.get(url)

driver.find_element_by_id('identifierId').send_keys('*****@*****.**')
driver.find_element_by_id("identifierNext").click()
time.sleep(5)
driver.find_element_by_class_name('whsOnd').send_keys('33456789')
driver.find_element_by_id('passwordNext').click()

driver.find_element_by_partial_link_text()
Пример #10
0
browser.get(start_url)
time.sleep(2)
# browser.maximize_window()
browser.find_element_by_xpath('//*[@id="search-form"]/div/div/div/div[2]/input'
                              ).click()  #검색창영역클릭 커서를 올려야함
browser.find_element_by_xpath(
    '//*[@id="search-form"]/div/div/div/div[2]/input').send_keys(
        '딩고 채널')  #검색창 영역에 원하는 youtuber입력
browser.find_element_by_xpath(
    '//*[@id="search-form"]/div/div/div/div[2]/input').send_keys(
        Keys.RETURN)  #엔터
time.sleep(2)

# browser.find_element_by_xpath('//*[@class="yt-simple-endpoint style-scope ytd-channel-renderer"]/div[2]/h3/span').click()

browser.find_element_by_partial_link_text('딩고').click()

browser.find_element_by_xpath(
    '//*[@class="scrollable style-scope paper-tabs"]/paper-tab[2]').click()

body = browser.find_element_by_tag_name('body')  # 스크롤하기 위해 소스 추출
num_of_pagedowns = 90
# 25번 밑으로 내리는 것
while num_of_pagedowns:
    body.send_keys(Keys.PAGE_DOWN)
    time.sleep(2)
    num_of_pagedowns -= 1
time.sleep(2)

html0 = browser.page_source
html = BeautifulSoup(html0, 'html.parser')
Пример #11
0
class Bot:
    def __init__(self, settings: Settings = None):
        self.settings = settings

        opts = ChromeOptions()
        if USER_DATA_DIR:
            opts.add_argument('user-data-dir=' + USER_DATA_DIR)
        opts.add_experimental_option("prefs", {
            "download.default_directory": DEFAULT_DOWNLOAD_DIRECTORY,
            "download.prompt_for_download": False,
            "download.directory_upgrade": True,
            "safebrowsing_for_trusted_sources_enabled": False,
            "safebrowsing.enabled": False
        })

        self.driver = Chrome(executable_path=os.getcwd() + '/chromedriver.exe', options=opts)

        self.chat_messages = dict()
        self.telegram_bot = TelegramBot()

    def authorize(self, login, password):
        self.driver.get('https://www.shasso.com/sso/login?action=login')
        self.driver.find_element_by_id('loginform-customers_email_address').send_keys(login)
        self.driver.find_element_by_id('loginform-customers_password').send_keys(password)

        time.sleep(0.5)
        click(self.driver, self.driver.find_element_by_xpath("//button[text()='Login']"))

    def add_order(self, order: Order, price: float):
        logging.info(f'[{dt.datetime.now().isoformat()}] Add order: [{order}] with price {price}')

        self.driver.get('https://www.g2g.com/sell/index')

        try:
            trade_selection = Select(self.driver.find_element_by_xpath('//select[@id="service"]'))
            trade_selection.select_by_value('1')

            wait_element(self.driver, '//select[@id="game"]')
            random_sleep(delay=0.3)

            game_selection = Select(self.driver.find_element_by_xpath('//select[@id="game"]'))
            game_selection.select_by_visible_text(
                f'World Of Warcraft ({order.region.upper()})'
            )

            wait_element(self.driver, "//h3[contains(text(), 'Product Details')]")
            random_sleep(delay=0.3)
            # ------------------------------------------------------------------------------------------

            server_selection = Select(self.driver.find_element_by_xpath("//select[@id='server']"))
            server_selection.select_by_visible_text(order.server)
            random_sleep()

            faction_selection = Select(self.driver.find_element_by_xpath("//select[@id='faction']"))
            faction_selection.select_by_visible_text(order.faction)
            random_sleep()

            self.driver.find_element_by_id('C2cProductsListing_products_description').send_keys(order.description)

            currency_selection = Select(self.driver.find_element_by_xpath(
                "//select[contains(@id, 'products_base_currency')]"))
            currency_selection.select_by_value(order.currency.upper())
            random_sleep()

            self.driver.find_element_by_xpath("//input[@id='C2cProductsListing_products_price']") \
                .send_keys(str(price))
            random_sleep()

            self.driver.find_element_by_xpath("//input[@id='C2cProductsListing_forecast_quantity']") \
                .send_keys(str(order.stock))
            random_sleep()

            self.driver.find_element_by_xpath("//input[@id='C2cProductsListing_minimum_quantity']") \
                .send_keys(str(order.min_unit_per_order))
            random_sleep()

            delivery_widget = self.driver.find_element_by_class_name('create__action-delivery')
            for span in delivery_widget.find_elements_by_class_name('create__action-duration'):
                if span.text.lower() in order.delivery_option.lower():
                    click(self.driver, span.find_element_by_tag_name('input'))
                    random_sleep(delay=-0.05)

            online_hrs_selection = Select(self.driver.find_element_by_xpath(
                "//select[@id='C2cProductsListing_online_hr']"
            ))
            online_hrs_selection.select_by_value(str(order.online_hrs))
            random_sleep()

            offline_hrs_selection = Select(self.driver.find_element_by_xpath(
                "//select[@id='C2cProductsListing_offline_hr']"
            ))
            offline_hrs_selection.select_by_value(str(order.offline_hrs))
            random_sleep()

            click(self.driver, self.driver.find_element_by_xpath("//button[contains(text(), 'Submit')]"))

        except Exception as e:
            logging.info(f'[{dt.datetime.now().isoformat()}] Error adding order: ' + str(e))

    def change_order(self, order: Order):
        logging.info(f'[{dt.datetime.now().isoformat()}] Changing order #{order.listing_number}')

        if order.region.lower() == 'eu':
            self.driver.get('https://www.g2g.com/sell/manage?service=1&game=2522&type=0')
        else:
            self.driver.get('https://www.g2g.com/sell/manage?service=1&game=2299')

        try:
            tr = self.driver.find_element_by_id(f'c2c_{order.listing_number}')
        except:
            logging.info(f'[{dt.datetime.now().isoformat()}] Order #{order.listing_number} not changed! Reason: not found')
            return

        def change_field(text):
            wait_element(self.driver, '//span[@class="editable-clear-x"]', timeout=2)
            click(self.driver, self.driver.find_element_by_class_name('editable-clear-x'))
            random_sleep()
            self.driver.find_element_by_class_name('input-large').send_keys(str(text))
            click(self.driver, self.driver.find_element_by_xpath("//button[@class='btn btn--green editable-submit']"))
            random_sleep(delay=0.5)

        try:
            class_name = ['g2g_actual_quantity', 'g2g_minimum_quantity', 'g2g_products_price']
            value = [str(order.stock), str(order.min_unit_per_order), str(order.price)]

            for i in range(len(class_name)):
                wait_element(self.driver, f'//a[contains(@class, "{class_name[i]}")]', timeout=2)
                field_to_write = tr.find_element_by_class_name(class_name[i])
                if field_to_write.text.strip() != value[i]:
                    click(self.driver, field_to_write)
                    random_sleep(delay=0.1)
                    change_field(value[i])

                    field_name = class_name[i][4:]
                    logging.info(
                        f'[{dt.datetime.now().isoformat()}] ' +
                        f'Order #{order.listing_number} Field "{field_name}" changed to {value[i]}')

            # CHANGE ONLINE / OFFLINE HOURS

            selection_classes = ['g2g_online_hr', 'g2g_offline_hr']
            selection_values = [str(order.online_hrs), str(order.offline_hrs)]

            for i in range(len(selection_classes)):
                wait_element(self.driver, f'//a[contains(@class, "{class_name[i]}")]', timeout=2)
                field_to_write = tr.find_element_by_class_name(selection_classes[i])
                if field_to_write.text.strip() != selection_values[i]:
                    click(self.driver, field_to_write)
                    random_sleep(delay=0.1)

                    selection = Select(self.driver.find_element_by_class_name('input-large'))
                    selection.select_by_visible_text(selection_values[i])
                    click(self.driver, self.driver.find_element_by_xpath("//button[@class='btn btn--green editable-submit']"))
                    random_sleep(delay=0.5)

                    field_name = selection_classes[i][4:]
                    logging.info(
                        f'[{dt.datetime.now().isoformat()}] ' +
                        f'Order #{order.listing_number} Field "{field_name}" changed to {selection_values[i]}')

        except:
            logging.info(f'[{dt.datetime.now().isoformat()}] Order #{order.listing_number} not changed! Error: ' +
                         str(sys.exc_info()[0]))
            return

        time.sleep(1)
        logging.info(f'[{dt.datetime.now().isoformat()}] Order #{order.listing_number} successfully changed')

    def active_orders(self, region='eu', active_status = True):
        logging.info(f'[{dt.datetime.now().isoformat()}] Started parsing active orders. Region: {region}')

        orders = []
        try:
            # create set of files that are currently in the directory
            current_xls_files = {file for file in os.listdir(DEFAULT_DOWNLOAD_DIRECTORY)
                                 if file.endswith('.xls')}

            if region == 'eu':
                url = 'https://www.g2g.com/sell/manage?service=1&game=2522&type=1'
            else:
                url = 'https://www.g2g.com/sell/manage?service=1&game=2299&type=1'
            self.driver.get(url)

            enable_download_headless(self.driver, DEFAULT_DOWNLOAD_DIRECTORY)
            click(self.driver, self.driver.find_element_by_partial_link_text('Download List'))
            time.sleep(3)

            new_file_name = {file for file in os.listdir(DEFAULT_DOWNLOAD_DIRECTORY)
                             if file.endswith('.xls') and file not in current_xls_files}.pop()
            new_file_path = os.path.join(DEFAULT_DOWNLOAD_DIRECTORY, new_file_name)

            orders = orders_from_excel(new_file_path, just_active=active_status)

            os.remove(new_file_path)
        except Exception as e:
            logging.info(f'[{dt.datetime.now().isoformat()}] Error parsing active orders: ' + str(e))

        logging.info(f'[{dt.datetime.now().isoformat()}] Parsed active orders successfully. Return {len(orders)} orders')
        return orders

    def activate_all(self):
        logging.info(f'[{dt.datetime.now().isoformat()}] Activate all orders started')

        def activate():
            try:
                click(self.driver, self.driver.find_element_by_id('check-all'))
            except:  # No inactive orders
                return

            for span in self.driver.find_elements_by_class_name('manage__action-text'):
                if 'relist' in span.text.lower():
                    click(self.driver, span)
                    break

            time.sleep(1)
            click(self.driver, self.driver.find_element_by_xpath("//button[@class='btn btn--green product-action-page']"))

        self.driver.get('https://www.g2g.com/sell/manage?service=1&game=2522&type=2')
        activate()

        self.driver.get('https://www.g2g.com/sell/manage?service=1&game=2299&type=2')
        activate()

        logging.info(f'[{dt.datetime.now().isoformat()}] Orders activated')

    def deactivate_all(self):
        logging.info(f'[{dt.datetime.now().isoformat()}] Deactivate all orders started')

        def deactivate():
            try:
                click(self.driver, self.driver.find_element_by_id('check-all'))
            except: # No inactive orders
                return

            for span in self.driver.find_elements_by_class_name('manage__action-text'):
                if 'deactivate' in span.text.lower():
                    click(self.driver, span)
                    break

            time.sleep(1)
            click(self.driver, self.driver.find_element_by_xpath("//button[@class='btn btn--green product-action-page']"))

        self.driver.get('https://www.g2g.com/sell/manage?service=1&game=2522&type=1')
        deactivate()

        self.driver.get('https://www.g2g.com/sell/manage?service=1&game=2299&type=1')
        deactivate()

        logging.info(f'[{dt.datetime.now().isoformat()}] Orders deactivated')

    def parse_messages(self):
        logging.info(f'[{dt.datetime.now().isoformat()}] Parse messages started')

        self.driver.get('https://chat.g2g.com/')
        time.sleep(1)
        wait_element(self.driver, "//input[@placeholder='Search']", timeout=30)

        usernames = list(map(lambda _div: _div.text.strip(),
                             self.driver.find_elements_by_class_name('e0e0377cd4a6e9dcec5b509beb659b00')))

        # FIRST PARSING
        if self.chat_messages == dict():
            usernames = iter(usernames)
            for div in self.driver.find_elements_by_class_name('_4f2b5b47720b4ebd54a6176cbe380a22'):
                self.chat_messages[next(usernames)] = [div.text.strip()]

            return

        try:
            for chat_number in range(3):
                try:
                    username = usernames[chat_number]
                    if username not in self.chat_messages:
                        self.chat_messages[username] = ['']

                    click(self.driver,
                          self.driver.find_elements_by_class_name('ff2c5f905d92eebf09f923b4a8bd3870')[chat_number])

                    try:
                        wait_element(self.driver, "//div[@message-id]", timeout=20)
                    except TimeoutError:  # No messages
                        continue
                    time.sleep(2)

                    new_messages = list(map(lambda span: span.text.strip(),
                                            self.driver.find_elements_by_xpath("//div[@message-id]")))

                    if new_messages[-1].split('\n')[0] == self.chat_messages[username][-1].split('\n')[0]:
                        continue

                    new_messages_start_index = len(new_messages) - 1

                    while new_messages_start_index > 0:
                        if new_messages[new_messages_start_index].split('\n')[0] == \
                                self.chat_messages[username][-1].splt('\n')[0]:
                            break
                        new_messages_start_index -= 1
                    new_messages = new_messages[new_messages_start_index:]

                    msg_to_send = username + '\n' + '\n\n'.join([
                        '\n'.join(nm.split('\n')[::-1]) for nm in new_messages
                    ])

                    self.chat_messages[username].extend(new_messages)

                    self.telegram_bot.send_msg(msg_to_send)

                except Exception as e:
                    logging.info(f'[{dt.datetime.now().isoformat()}] Error parsing chat '
                                 + usernames[chat_number] + ': ' + str(e))
        except Exception as e:
            logging.info(f'[{dt.datetime.now().isoformat()}] Error parsing chats: ' + str(e))

    def close(self):
        self.driver.close()
Пример #12
0
class OpenAir(object):
    def __init__(self, headless=False):
        options = ChromeOptions()
        options.add_argument("disable-extensions")
        options.add_argument("incognito")
        if headless:
            options.add_argument("headless")
        if os.name == 'nt':
            path_to_chrome = str(Path('./chromedriver.exe').relative_to('.'))
        else:
            path_to_chrome = str(Path('./chromedriver').absolute())
        self.browser = Chrome(path_to_chrome, options=options)

    def logging_in(self, login, password):
        self.browser.get(
            'https://psa.industrysoftware.automation.siemens.com/dashboard.pl?action=paint;_api=673220;app=ma;uid=0C_784Rz6BGcckbUO344ug;r=CQipU0r8675'
        )
        self.wait_until_css_element_object_found('#username')
        self.browser.find_element_by_css_selector('#username').send_keys(login)
        # self.browser.find_element_by_css_selector('#emailaddress').send_keys(login)
        self.browser.find_element_by_css_selector('#password').send_keys(
            password)
        self.browser.find_element_by_css_selector('.btn-yellow').submit()
        input("Enter your PKI card info and THEN hit Enter here => ")

    def create_new_time_sheet(self, send_date, project_dict):
        self.wait_until_css_element_object_found('#oa3_toolbox_create_new')
        self.browser.find_element_by_css_selector(
            '#oa3_toolbox_create_new').click()
        self.wait_until_css_element_object_found('#oa3_global_create_new')
        self.browser.find_element_by_link_text(
            'Timesheets: Timesheet, New').click()
        self.wait_until_css_element_object_found('select[name="range"]')
        self.browser.find_element_by_css_selector(
            'select[name="range"]').send_keys('Other')
        self.browser.find_element_by_css_selector('#date').send_keys(send_date)
        self.browser.find_element_by_css_selector('input[name="save"]').click()
        error_list = self.browser.find_elements_by_css_selector('span.err_msg')
        if error_list:
            for each_text in error_list:
                print(each_text.text)
                self.browser.find_element_by_css_selector(
                    '.nav_active').click()
                self.wait_until_css_element_object_found('#list_data')
                sleep(3)
                for each_open_time_sheet in self.browser.find_elements_by_css_selector(
                        '#list_data .listCellContent_sheetname'):
                    if send_date in each_open_time_sheet.find_element_by_partial_link_text(
                            'Timesheet').text:
                        each_open_time_sheet.click()
                        self._selecting_projects_and_tasks2(project_dict)
                        break
        else:
            self._selecting_projects_and_tasks2(project_dict)

    def _selecting_projects_and_tasks2(self, project_task_week_hours_dict):
        for index_project, each_project in enumerate(
                project_task_week_hours_dict):
            self.wait_until_css_element_object_found('#ts_c1_r' +
                                                     str(index_project + 1))
            self.browser.find_element_by_css_selector(
                '#ts_c1_r' + str(index_project + 1)).send_keys(each_project)
            hours_worked = [0] * 7
            for each_task in project_task_week_hours_dict[each_project]:
                self.browser.find_element_by_css_selector(
                    '#ts_c2_r' + str(index_project + 1)).send_keys(each_task)
                self.browser.find_element_by_css_selector(
                    '#ts_pte_' + str(index_project + 1)).send_keys('0.00')
                for each_date in project_task_week_hours_dict[each_project][
                        each_task]:
                    if 'Mon' in each_date:
                        hours_worked[0] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
                    elif 'Tue' in each_date:
                        hours_worked[1] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
                    elif 'Wed' in each_date:
                        hours_worked[2] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
                    elif 'Thur' in each_date:
                        hours_worked[3] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
                    elif 'Fri' in each_date:
                        hours_worked[4] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
                    elif 'Sat' in each_date:
                        hours_worked[5] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
                    elif 'Sun' in each_date:
                        hours_worked[6] = project_task_week_hours_dict[
                            each_project][each_task][each_date]
            for index_day, each_day in enumerate(hours_worked):
                self.browser.find_element_by_css_selector(
                    '#ts_c' + str(index_day + 3) + '_r' +
                    str(index_project + 1)).send_keys(each_day)
        self.browser.find_element_by_css_selector(
            '#timesheet_savebutton').click()
        # self._submit_time_sheet()

    def find_all_projects(self, project_file_name_to_save):
        project_structure = {}
        self.wait_until_css_element_object_found('#ts_c1_r1 option')
        for each_project in self.browser.find_elements_by_css_selector(
                '#ts_c1_r1 option'):
            project_name = each_project.text
            if project_name:
                self.browser.find_element_by_css_selector(
                    '#ts_c1_r1').send_keys(project_name)
                tasks_esx = self.browser.find_elements_by_css_selector(
                    '#ts_c2_r1 option')
                tasks_list = []
                for each_task in tasks_esx:
                    if each_task:
                        tasks_list.append(each_task.text)
                project_structure[project_name] = tasks_list
        with open(project_file_name_to_save, 'w') as out:
            out.write(json.dumps(project_structure, indent=4) + '\n')
        self.browser.quit()

    def selecting_projects_and_tasks(self):
        self.browser.find_element_by_css_selector('#ts_c2_r1').send_keys(
            'Siemens PLM Internal : Utilized Internal')
        self.browser.find_element_by_css_selector('#ts_c2_r1').send_keys('3')
        self.browser.find_element_by_css_selector('#ts_pte_1').send_keys(
            '0.00')
        # Mon to Fri
        hours_worked = [8, 8, 8, 8, 8, 0, 0]
        for index_day, each_day in enumerate(hours_worked):
            self.browser.find_element_by_css_selector(
                '#ts_c' + str(index_day + 3) + '_r1').send_keys(each_day)
        # self.browser.find_element_by_css_selector('#timesheet_savebutton').click()

    def _go_to_existing_time_sheet(self):
        self.wait_until_css_element_object_found('div.dash_portlet-content')
        self.browser.find_element_by_partial_link_text(
            'Open Timesheet').click()

    def _get_all_open_time_sheets(self, open_time_sheet_location_to_save):
        unsubmitted_time_sheets = []
        self.wait_until_css_element_object_found('#list_data')
        for each_open_time_sheet in self.browser.find_element_by_css_selector(
                '#list_data').find_elements_by_css_selector(
                    '.listCellContent_sheetname'):
            unsubmitted_time_sheets.append(
                each_open_time_sheet.find_element_by_partial_link_text(
                    'Timesheet').text)
        with open(open_time_sheet_location_to_save, 'w') as out:
            out.write(json.dumps(unsubmitted_time_sheets, indent=4) + '\n')
        for index, each_unsubmit_time_sheet in enumerate(
                unsubmitted_time_sheets):
            print('{}.) {}'.format(index, each_open_time_sheet.text))
        which_time_sheet = input('Choose a number that you want to update?=> ')
        self.browser.find_element_by_css_selector(
            '#list_data').find_elements_by_css_selector(
                '.listCellContent_sheetname')[int(which_time_sheet)].click()

    def _select_from_open_time_sheets(self):
        my_test = 'Timesheet for 04/01/19 to 04/07/19'
        for each_open_time_sheet in self.browser.find_element_by_css_selector(
                '#list_data').find_elements_by_css_selector(
                    '.listCellContent_sheetname'):
            if each_open_time_sheet.find_element_by_partial_link_text(
                    'Timesheet').text == my_test:
                each_open_time_sheet.find_element_by_partial_link_text(
                    'Timesheet').click()
                break

    def _submit_time_sheet(self):
        self.wait_until_css_element_object_found('td.nav_item_options a')
        self.browser.find_elements_by_css_selector(
            'td.nav_item_options a')[3].click()
        self.wait_until_css_element_object_found('#formButtonsBottom input')
        self.browser.find_elements_by_css_selector(
            '#formButtonsBottom input')[1].click()
        self.browser.quit()

    def wait_until_css_element_object_found(self, css_param, wait_time=10):
        wait = WebDriverWait(self.browser, wait_time)
        wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, css_param)))
Пример #13
0
        print("zh-CN present in task. 26-markets tamplate will be used")
    adjusted_table_list = adjusted_table.splitlines()
    list_of_adjusted = []
    for x in adjusted_table_list[1:]:
        list_of_adjusted.append(float(x.split(" ")[-1]))
    markets = len(adjusted_table_list) - 1
    minimal_adjusted = round(min(list_of_adjusted))
    maximal_adjusted = round(max(list_of_adjusted))
    print(
        f"{pom-1}.\tJob ID: {job_number}; Markets: {markets}; Minimal adjusted: {minimal_adjusted}; Maximal adjusted: {maximal_adjusted}"
    )

    sheet.cell(row=pom, column=4).value = markets
    sheet.cell(row=pom, column=5).value = minimal_adjusted

    xliff_link = browser.find_element_by_partial_link_text("xliffs.zip")
    xliff_link.click()
    time.sleep(3)

    shutil.move(f"c:\\Users\\SlavP\\Downloads\\xliffs.zip",
                dirpath + f"\\00_source\\{job_number}.zip")
    pom += 1

if xbox_25:
    os.remove("01_CreateProject___XBOX_26.cmd")
else:
    os.remove("01_CreateProject___XBOX_25.cmd")

book.save('reference.xlsx')
print("Table saved. DONE")
browser.close()
Пример #14
0
    index += 1

    soup = BeautifulSoup(browser.page_source, features='lxml')
    total = int(soup.find('div', class_='page-total').text[1:-1].strip())

    string = f'\rLoading:[{"#" * (index//(total//100 + 1))}{" " * ((total-index)//(total//100 + 1))}]'
    stdout.write(string)
    stdout.flush()

    companies = soup.find_all('div', class_='info')
    for company in companies:
        company_list.append(handler(company))

    while True:
        try:
            btn = browser.find_element_by_partial_link_text('下一頁')
            btn.click()
            break
        except:
            sleep(1)

    if index == total:
        browser.quit()
        break
time_f = datetime.now()
print(f'\nThe soup is done! (cost {(time_f-time_s).seconds} seconds.)')

import csv
with open('company_list.csv', 'w', encoding='big5', errors='ignore') as f:
    writer = csv.writer(f)
    writer.writerows(company_list)
Пример #15
0
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
import time
import re  #re.compile()關鍵字篩選

driver = Chrome("./chromedriver")
driver.get("https://www.marathonsworld.com/artapp/racelist.php?p=1")  #開啟網址
time.sleep(10)  #因網頁開啟緩慢需等待10秒以上
continue_link = driver.find_element_by_partial_link_text('trainingDaily')
print(continue_link)
driver.close()
Пример #16
0
class GoogleSpider:
    driver = None
    keyword = None
    time_out = 1

    def __init__(self,
                 keyword,
                 proxy_server,
                 thread_count=5,
                 chrome_dir='ChromeData',
                 chrome_path='chrome',
                 chrome_port=9787,
                 ):
        self.keyword = keyword
        # selenium远程连接Chrome
        # 代理 例--proxy-server=socks5://127.0.0.1:9090
        os.popen(
            '{} --remote-debugging-port={} --user-data-dir={} {}'.format(chrome_path, chrome_port, chrome_dir, '--proxy-server=' + proxy_server if proxy_server else ''))
        options = ChromeOptions()

        # 远程连接Chrome
        options.add_experimental_option(
            'debuggerAddress', '127.0.0.1:{}'.format(chrome_port))

        desired_capabilities = DesiredCapabilities().CHROME
        desired_capabilities['pageLoadStrategy'] = 'none'
        self.driver = Chrome(
            options=options, desired_capabilities=desired_capabilities)
        super().__init__()

    def driver_get(self, url):
        self.driver.get(url)
        time.sleep(self.time_out)
        while 'www.google.com/sorry' in self.driver.current_url:
            time.sleep(1)

    def start(self):
        def parse_article_url():
            while 'www.google.com/sorry' in self.driver.current_url:
                time.sleep(1)
            time.sleep(2)
            for i in self.driver.find_elements_by_class_name('g'):
                url = i.find_element_by_tag_name(
                    'a').get_attribute('href').strip()
                if 'https://www.google.com/' not in url:
                    print(url)

                    with open('google.txt', 'a') as f:
                        f.write(url + '\n')

        self.driver_get(
            'https://www.google.com/search?q={}'.format(self.keyword))
        time.sleep(2)
        while True:
            while True:
                try:
                    parse_article_url()
                    break
                except NoSuchElementException as e:
                    print(e)
                    time.sleep(1)
            try:
                while 'www.google.com/sorry' in self.driver.current_url:
                    time.sleep(1)
                next_element = self.driver.find_element_by_id('pnnext')
                if not next_element:
                    next_element = self.driver.find_element_by_partial_link_text(
                        'Next')

                if not next_element:
                    next_element = self.driver.find_element_by_partial_link_text(
                        '下一页')
                if not next_element:
                    next_element = self.driver.find_element_by_partial_link_text(
                        '下一頁')
                next_element.click()
            except NoSuchElementException as __:
                self.time_out += 1
                if self.time_out >= 10:
                    break