Exemple #1
0
 def hose_stock_list():
     global webdriver
     chrome_driver_path = 'D:\python\selenium\driver\chromedriver.exe'
     chrome_options = Options()
     #chrome_options.page_load_strategy
     #chrome_options.add_argument('--headless')
     chrome_options.add_argument(
         '--user-data-dir=C:\\Users\\hung-pro7\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Default'
     )
     webdriver = webdriver.Chrome(executable_path=chrome_driver_path,
                                  options=chrome_options)
     url = 'https://trade-hcm.vndirect.com.vn/chung-khoan/hose'
     webdriver.get(url)
     webdriver.find_element_by_xpath('//*[@id="menuWrp"]/div/a[2]').click()
     time.sleep(2)
     webdriver.find_element_by_xpath(
         '//*[@id="login-popup"]/form/div[1]/div/input').send_keys(
             "tuanhungstar")
     webdriver.find_element_by_xpath(
         '//*[@id="login-popup"]/form/div[2]/div/input').send_keys(
             "Khanhha-1")
     webdriver.find_element_by_xpath(
         '//*[@id="login-popup"]/form/button').click()
     time.sleep(2)
     webdriver.find_element_by_xpath(
         '//*[@id="nav"]/ul[1]/li[2]/a/span').click()
     time.sleep(2)
     HOSE_table = webdriver.find_elements_by_class_name('txt-gia-tran')
     HOSE_ticker = []
     for row in HOSE_table:
         text = row.get_attribute('id').replace('ceil', '')
         HOSE_ticker.append(text)
     return HOSE_ticker
Exemple #2
0
def check_exists_by_xpath(xpath):
    
    try:
        webdriver.find_element_by_xpath(xpath)
    except NoSuchElementException:
        return False
    return True
 def clickFollowButton(self, webdriver, val, stopFlag, file_object):
     try:
         follow_button = webdriver.find_element_by_xpath(
             self.follow_list_item + str(val) + ']/button')
         follow_id = webdriver.find_element_by_xpath(self.follow_list_item +
                                                     str(val) +
                                                     ']/span/b/span/a')
         if follow_id in self.followed_list:
             return stopFlag
         file_object.write(follow_id.text + '\n')
         webdriver.execute_script("return arguments[0].scrollIntoView();",
                                  follow_button)
         webdriver.execute_script("window.scrollBy(0, -" +
                                  str(random.randint(150, 200)) + ")")
         sleep(random.uniform(.5, 6))
         follow_button.click()
         sleep(random.uniform(.5, 2))
         follow_text = webdriver.find_element_by_xpath(
             self.follow_list_item + str(val) + ']/button/span')
         if follow_text.text == 'Follow':
             print('Hit Max Follows Stopping')
             stopFlag = False
             return stopFlag
         follow_text = webdriver.find_element_by_xpath(
             self.follow_list_item + str(val) + ']/button/span')
         webdriver.execute_script("window.scrollBy(0, -" +
                                  str(random.randint(10, 50)) + ")")
         name = webdriver.find_element_by_xpath(self.follow_list_item +
                                                str(val) +
                                                ']/span/b/span/a')
     except:
         print("Follow Button Not Present: " + str(val))
     return stopFlag
def unfollower_func():
    try:
        # CLICKING THE CROSS BUTTON
        webdriver.find_element_by_css_selector(
            'body > div.RnEpo.Yx5HN > div > div > div:nth-child(1) > div > div:nth-child(3) > button > svg').click()
        
        unfollow = webdriver.find_element_by_xpath(
            '/html/body/div[1]/section/main/div/header/section/div[1]/div[2]/span/span[1]/button/div/span')

        unfollow.click()
        sleep(5)
        # CONFIRMING UNFOLLOW
        webdriver.find_element_by_css_selector(
            'body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.-Cab_').click()

    except NoSuchElementException:
        # CLICKING THE CROSS BUTTON
        webdriver.find_element_by_css_selector(
            'body > div.RnEpo.Yx5HN > div > div > div:nth-child(1) > div > div:nth-child(3) > button > svg').click()

        unfollow = webdriver.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/div[1]/button')
        unfollow.click()
        sleep(5)

        # CONFIRMING UNFOLLOW
        webdriver.find_element_by_css_selector(
            'body > div.RnEpo.Yx5HN > div > div > div.mt3GC > button.aOOlW.-Cab_').click()
Exemple #5
0
def click_to_designers(webdriver):
    '''
    Navigates towards the sub-menu on the website that contains the "filter by designer"
    section.
    
    --------------------------------------------------------------------------------------------
    Input:
    webdriver: Selenium webdriver object
    --------------------------------------------------------------------------------------------
    Output:
    return: List of all the different designers that are available for selection in the submenu.
    Allows us to build a list, and create a smart list that allows us to intellegently restart
    the webscrapper if it crashes.
    '''
	designer_menu = webdriver.find_element_by_xpath('//div[@class="designers-wrapper _collapsed"]')
	designer_menu_button = designer_menu.find_element_by_xpath('.//div[@class="-collapsible-target"]')
	designer_menu_button.click()

	time.sleep(1)

	designer_cat_button = webdriver.find_element_by_xpath('//button[@title="View all designers"]')
	designer_cat_button.click()

	time.sleep(1)

	temp = webdriver.find_element_by_xpath('//div[@class="designers-popover"]')
	button = temp.find_element_by_xpath('.//div[@class="tabs"]/span')
	button.click()

	time.sleep(1)

	return(temp.find_element_by_xpath('.//div[@class="content"]'))
def main():
    items = []

    #Log in
    webdriver.get(MAIN_PAGE_URL)
    webdriver.find_element_by_id(
        'ctl00_ContentPlaceHolder1_Username').send_keys(
            credentials['username'])
    webdriver.find_element_by_id(
        'ctl00_ContentPlaceHolder1_Password').send_keys(
            credentials['password'])
    webdriver.find_element_by_name('ctl00$ContentPlaceHolder1$ctl04').click()

    #Set items to show = 100
    webdriver.find_element_by_xpath(
        "//select[@name='ctl00$ContentPlaceHolder1$GridView1$ctl13$ctl11']/option[text()='100']"
    ).click()
    #Getting number of pages
    page_number = len(
        webdriver.find_elements_by_xpath(
            "//tr[@class='grid-pager']//table//tr/td[not(@class)]"))
    page_href_script = "__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Page$%s')"

    #Extracting each page on the website
    for i in range(page_number):
        i += 1
        if i != 1:
            webdriver.execute_script(page_href_script % i)
            # Wait for redirecting
            time.sleep(10)
        items += extract()

    #Insert into database all extracted items (rigs)
    insert_into_database(items)
Exemple #7
0
def attack_captcha(webdriver, idx):

    now_time = datetime.now().strftime('%s')

    elem = webdriver.find_element_by_xpath('//*[@id="num_img"]')
    url = elem.get_attribute('src')
    f = io.BytesIO(request.urlopen(url).read())
    img = Image.open(f)
    img_path = './img/' + now_time + '.jpg'
    img.save(img_path)
    img_arr = np.asarray(img) / 255

    pre_label = model.predict(img_arr)

    time.sleep(1)

    write = str(pre_label)

    webdriver.find_element_by_xpath('/html/body/form/p[1]/input').send_keys(write)

    print("idx: ", idx, "predict:", write)

    time.sleep(1)

    webdriver.find_element_by_xpath('/html/body/form/p[2]/input').click()

    message = webdriver.find_elements_by_css_selector('p.ans')

    print("idx: ", idx, "message:", message[0].text)

    time.sleep(3)

    webdriver.quit()
Exemple #8
0
def login(webdriver):
    # Open the instagram login page
    webdriver.get(
        'https://www.instagram.com/accounts/login/?source=auth_switcher')
    # sleep for 3 seconds to prevent issues with the server
    time.sleep(3)
    # Find username and password fields and set their input using our constants
    username = webdriver.find_element_by_name('username')
    username.send_keys('*****@*****.**')
    password = webdriver.find_element_by_name('password')
    password.send_keys('Aida72584')
    # Get the login button
    try:
        button_login = webdriver.find_element_by_xpath(
            '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[4]/button'
        )
    except:
        button_login = webdriver.find_element_by_xpath(
            '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[6]/button/div'
        )
    # sleep again
    time.sleep(2)
    # click login
    button_login.click()
    time.sleep(3)
    # In case you get a popup after logging in, press not now.
    # If not, then just return
    try:
        notnow = webdriver.find_element_by_css_selector(
            'body > div.RnEpo.Yx5HN > div > div > div.mt3GC > button.aOOlW.HoLwm'
        )
        notnow.click()
    except:
        return
Exemple #9
0
def order_to_string(webdriver, order_number, domain):

    webdriver.get(
        f"https://{domain}/admin/orders.php?page=1&oID={order_number}&action=edit&ro=1#wysylka"
    )

    # receiver info
    receiver_form_address_group = webdriver.find_element_by_xpath(
        "//*[@id='receiverForm']/div")
    rows_receive = receiver_form_address_group.find_elements_by_xpath(
        "./div[starts-with(@class,'row')]")
    contents = []
    for row in rows_receive:
        try:
            contents.append(
                row.find_element_by_xpath("./div[@class='content']"))
        except:
            continue

    # shipment info
    shipment_form_adrress_group = webdriver.find_element_by_xpath(
        "//*[@id='shipmentForm']/div")
    rows_ship = shipment_form_adrress_group.find_elements_by_xpath(
        "./div[starts-with(@class,'row')]")
    for row in rows_ship:
        try:
            contents.append(
                row.find_element_by_xpath("./div[@class='content']"))
        except:
            continue
    final_list = [content.text for content in contents if (content.text != '')]
    final_list.insert(0, str(order_number))
    sleep(3)
    return ' '.join(map(str, final_list))  # formatting this list into a string
    def login(server_url, webdriver):

        webdriver.get(server_url)

        # Click login link, switch to persona window
        webdriver.find_element_by_id('login').click()
        webdriver.switch_to_window('__persona_dialog')

        # Enter email address and password
        email_address_input = WebDriverWait(webdriver, 5).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="authentication_email"]')))
        email_address_input.send_keys(config.PERSONA_USER)
        webdriver.find_element_by_xpath('//*[@id="authentication_form"]/p[4]/button[1]').click()

        password_input = WebDriverWait(webdriver, 10).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="authentication_password"]')))
        password_input.send_keys(config.PERSONA_PASS)

        # Submit login form and switch back to previous window
        webdriver.find_element_by_xpath('//*[@id="authentication_form"]/p[4]/button[3]').click()
        webdriver.switch_to_window('')

        # Wait until profile name is clickable
        WebDriverWait(webdriver, 10).until(
            EC.element_to_be_clickable((By.ID, 'profile')))
Exemple #11
0
 def runFollowersFollow(self, webdriver, person, account, stopFlag):
     sleep(2)
     webdriver.get('https://www.%s.com/%s/followers/' %
                   (str.lower(account.accountType), person))
     sleep(1)
     follow_list = webdriver.find_elements_by_xpath(self.follow_list)
     maxVal = len(follow_list)
     followDoc = open("./bot_docs/masterList.txt", "a")
     for index in range(1, 10):
         try:
             followButton = webdriver.find_element_by_xpath(
                 self.follow_list_item + str(index) + ']/div/div[3]/button')
             accountName = webdriver.find_element_by_xpath(
                 self.follow_list_item + str(index) +
                 ']/div/div[2]/div[1]/div/div/a')
             webdriver.execute_script(
                 "return arguments[0].scrollIntoView();", followButton)
             sleep(random.uniform(0, 1))
             # if(followButton.text=='Follow' and accountName.text not in clickedList.split(',')[0]):
             #     followButton.click()
             #     followDoc.write(accountName.text + ', ' + accountName.get_attribute("href") + datetime.today().strftime('%Y-%m-%d') + '\n')
         except:
             print("no follow button: " + self.follow_list_item +
                   str(index) + ']/div/div[3]/button')
     followDoc.close()
 def find_database_field(webdriver):
     # Should be able to use get_element_by_id but duplicate ids in page
     input = webdriver.find_element_by_xpath('//input[@id="database"]')
     select = webdriver.find_element_by_xpath('//select[@id="database"]')
     if select.is_displayed():
         return select
     if input.is_displayed():
         return input
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)
Exemple #14
0
 def code_1(self, webdriver, code: str):
     wait_for_element = WebDriverWait(webdriver, TIMEOUT).until(
         EC.element_to_be_clickable((By.XPATH, '//*[@id="code"]')))
     webdriver.find_element_by_xpath('//*[@id="code"]').send_keys(code)
     wait_for_element = WebDriverWait(webdriver, TIMEOUT).until(
         EC.element_to_be_clickable((By.XPATH, '//*[@id="continue"]/span')))
     webdriver.find_element_by_xpath('//*[@id="continue"]/span').click()
     self.status = 'Epicgames account registered'
def login_by_password(webdriver, username_xpath, user_name, password_xpath,
                      password, login_btn_xpath):
    username_input = webdriver.find_element_by_xpath(username_xpath)
    username_input.send_keys(user_name)
    password_input = webdriver.find_element_by_xpath(password_xpath)
    password_input.send_keys(password)
    login_btn = webdriver.find_element_by_xpath(login_btn_xpath)
    login_btn.click()
Exemple #16
0
 def test_baidu(self):
     webdriver = self.driver
     webdriver.get(self.base_url + "/")
     webdriver.find_element_by_id('translateContent').clear()
     webdriver.find_element_by_id('translateContent').send_keys("webdriver")
     webdriver.find_element_by_xpath('//*[@id="form"]/button').click()
     time.sleep(2)
     title = webdriver.title
     self.assertEqual(
         title, "【webdriver】什么意思_英语webdriver的翻译_音标_读音_用法_例句_在线翻译_有道词典")
 def runLogin(self, webdriver, account):
     webdriver.get('https://www.%s.com' % (str.lower(account.accountType)))
     sleep(2)
     login_button = webdriver.find_element_by_xpath(self.login_button)
     login_button.click()
     email = webdriver.find_element_by_xpath(self.email_input)
     email.send_keys(account.email)
     password = webdriver.find_element_by_xpath(self.password_input)
     password.send_keys(account.password)
     sleep(2)
     password.send_keys(Keys.RETURN)
def publish_article_in_wechat(webdriver):
    publish_btn_xpath = '//*[@id="js_send"]'
    wait_element_visible(webdriver, publish_btn_xpath)
    publish_btn = webdriver.find_element_by_xpath(publish_btn_xpath)
    webdriver.execute_script('arguments[0].click()', publish_btn)
    # publish_btn.click()
    group_publish_btn_xpath = '//*[@id="send_btn_main"]/div/a/label'
    wait_element_visible(webdriver, group_publish_btn_xpath)
    group_publish_btn = webdriver.find_element_by_xpath(
        '//*[@id="send_btn_main"]/div/a/label')
    group_publish_btn.click()
def validate(xPath):
    href = str(webdriver.find_element_by_xpath(xPath+'tr[1]/td[2]/a').get_attribute("href")).strip()
    if href not in prev_star_matching_list:
        age = int(str(webdriver.find_element_by_xpath(xPath+'tr[2]/td[2]').text).strip())
        height = int(str(webdriver.find_element_by_xpath(xPath+'tr[2]/td[4]').text).strip())
        star = str(webdriver.find_element_by_xpath(xPath+'tr[3]/td[4]').text).strip()
        if age >= 28:
            if age <= 32:
                if height > 163:
                    if star in validStars:
                        prev_star_matching_list.append(href)
Exemple #20
0
def siteLogin(webdriver, username, password):
    signInLink = webdriver.find_element_by_xpath(signInLinkPath)
    signInLink.click()
    signInUser = webdriver.find_element_by_xpath(signInUserPath)
    signInUser.send_keys(username)
    signInNext = webdriver.find_element_by_xpath(signInNextPath)
    signInNext.click()
    signInPass = webdriver.find_element_by_xpath(signInPassPath)
    signInPass.send_keys(password)
    signInButn = webdriver.find_element_by_xpath(signInButnPath)
    signInButn.click()
Exemple #21
0
 def hashtagFollow(self, webdriver, file_object):
     sleep(random.uniform(.5, 1))
     followButton = webdriver.find_element_by_xpath(self.follow_button)
     accountName = webdriver.find_element_by_xpath(self.account_name)
     # if(followButton.text=='Follow' and accountName.text not in clickedList):
     if (followButton.text == 'Follow'):
         followButton.click()
         file_object.write(accountName.text + '\n')
     sleep(random.uniform(.5, 2))
     if (followButton.text == 'Follow'):
         return False
     return True
Exemple #22
0
def scrape_olr(neighborhood_code, webdriver):
    username =  os.getenv('JRX_USER')
    password = os.getenv('JRX_PASSWORD')

    if not username or not password:
        raise Exception('The environment variables JRX_USER and JRX_PASSWORD must be set.')
    
    username_input = webdriver.find_element_by_id('ctl00_ContentPlaceHolder1_txtUserName')
    password_input = webdriver.find_element_by_id('ctl00_ContentPlaceHolder1_txtPassword')

    username_input.send_keys(username)
    time.sleep(1)
    password_input.send_keys(password)

    login_button = webdriver.find_element_by_id('ctl00_ContentPlaceHolder1_Loginexceed')
    time.sleep(1)
    login_button.click()
    time.sleep(1)

    customer_link = webdriver.find_element_by_xpath("//a[@data-label='View Customers']")
    webdriver.execute_script("arguments[0].click();", customer_link)
    time.sleep(2)

    customer_grid = webdriver.find_element_by_xpath("//table[@id='ctl00_ctl00_MyCustContent_MyCustContent_gvParentAjax']")
    jr_tblentry = customer_grid.find_element_by_xpath("//tr[@id='tr_788817']")
    target_div = jr_tblentry.find_element_by_xpath("//div[@id='divDetail_788817']")

    # click on expand button
    expand_btn = customer_grid.find_element_by_xpath("//input[@id='imgExpColl_788817']")
    webdriver.execute_script("arguments[0].click();", expand_btn)
    time.sleep(1)

    #nested_tables = target_div.find_elements_by_tag_name('table')
    
    #print(dir(nested_tables))
    #print('### %d nested tables found in target div.' % len(nested_tables))
    #print('### found target table.')
    search_link_condos = target_div.find_element_by_xpath("//a[@href='MyCustomerImageHndlr.aspx?Type=Runsearch&SearchID=956274&RunSearchType=AdvancedSale&cid=788817&From=View']")
    webdriver.execute_script("arguments[0].click();", search_link_condos)

    time.sleep(1)
    top_div = webdriver.find_element_by_xpath("//div[@class='container_1130 search-ui']")
    detail_areas = top_div.find_elements_by_xpath("//div[@class='apt_details_area clearfix']")

    print('### %s listings found.' % len(detail_areas))
    for da in detail_areas:
        #apt_detail = da.find_element_by_xpath("//div[@class='apt_details_left']")
        markup = da.get_attribute('innerHTML')
        soup_parser = BeautifulSoup(markup, 'html.parser')        
        scrape_olr_condo_listings(soup_parser, markup)

        #print(markup)
        print('#################################################')
Exemple #23
0
 def auth_with_data(self, webdriver, login, pswd):
     self.login = login
     self.pswd = pswd
     webdriver.get('https://passport.yandex.ru/auth')
     wait_for_element = WebDriverWait(webdriver, TIMEOUT).until(
         EC.element_to_be_clickable(
             (By.XPATH, '//*[@id="passp-field-login"]')))
     webdriver.find_element_by_xpath(
         '//*[@id="passp-field-login"]').send_keys(self.login + Keys.RETURN)
     wait_for_element = WebDriverWait(webdriver, TIMEOUT).until(
         EC.element_to_be_clickable((By.NAME, 'passwd')))
     webdriver.find_element_by_name('passwd').send_keys(self.pswd +
                                                        Keys.RETURN)
def publish_article_in_jj(webdriver):
    publish_btn = webdriver.find_element_by_xpath(
        '//*[@id="juejin-web-editor"]/div[2]/header/div[2]/div[5]/div[1]/span')
    publish_btn.click()
    android_tag = webdriver.find_element_by_xpath(
        '//*[@id="juejin-web-editor"]/div[2]/header/div[2]/div[5]/div[2]/div[2]/div[2]/div[1]'
    )
    android_tag.click()
    publish_btn_xpath = '//*[@id="juejin-web-editor"]/div[2]/header/div[2]/div[5]/div[2]/button'
    wait_element_visible(webdriver, publish_btn_xpath)
    time.sleep(2)
    publish_btn = webdriver.find_element_by_xpath(publish_btn_xpath)
    publish_btn.click()
Exemple #25
0
 def wait_for_element(self, webdriver, path):
     limit = 1800   # waiting limit in seconds
     inc = 0.5   # in seconds; sleep for 500ms
     c = 0
     while (c < limit):
         try:
             print "Waiting... " + str(c)
             webdriver.find_element_by_xpath(path)
             print "Found!"
             return 1
         except Exception:  # the most diabolical python antipattern
             time.sleep(inc)
             c = c + inc
     print "The element hasn't been found."
def WaitForElement(webdriver, path):
    limit = 10   # waiting limit in seconds
    inc = 1   # in seconds; sleep for 500ms
    c = 0
    while (c < limit):
        try:
            webdriver.find_element_by_xpath(path)
            return 1        # Success
        except:
            time.sleep(inc)
            c = c + inc 
 
    # print sys.exc_info()
    return 0   
Exemple #27
0
def czy_sa_linki_do_czytania(driver):
    time.sleep(1)
    try:
        driver.find_element_by_xpath('//*[@id="tblFileData"]/tbody/tr[1]/td/a[1]')
    except:
        print("Nie ma linków do czytania! Strona: ",driver.current_url)
        return "NIE"
    return "TAK"


    try:
        webdriver.find_element_by_xpath(xpath)
    except NoSuchElementException:
        return False
def WaitForElement(webdriver, path):
    limit = 10  # waiting limit in seconds
    inc = 1  # in seconds; sleep for 500ms
    c = 0
    while (c < limit):
        try:
            webdriver.find_element_by_xpath(path)
            return 1  # Success
        except:
            time.sleep(inc)
            c = c + inc

    # print sys.exc_info()
    return 0
Exemple #29
0
def logIn(webdriver, login, password):
	email_el = webdriver.find_element_by_name("email")
	pass_el =  webdriver.find_element_by_name("pass")
	email_el.send_keys(login)
	pass_el.send_keys(password.decode("utf-8"))
	webdriver.find_element_by_xpath("//form[@id='login_form']//input[@type='submit']").click()
	current_url = webdriver.current_url
	print "url: " + current_url
	if "login.php" in current_url:
		print "Wrong login and/or password"
		return 0
	else:
		print "Succesfully logged in"
		return 1
Exemple #30
0
def updateUserStatus(webdriver, text):
	# Update status
	try:
		webdriver.find_element_by_xpath("//span[@id='composerTourStart']//a").click()
	except:
		print "Could not click on //span[@id='composerTourStart']//a "
	
	#status = wait_and_find_element(webdriver, "//form[@class='attachmentForm']//textarea[@name='xhpc_message_text']", 5)
	status = wait_and_find_element(webdriver, "//form[@class='attachmentForm']//textarea", 5)
	status.send_keys(text.decode("utf-8"))  # with the help from  http://themoritzfamily.com/python-encodings-and-unicode.html
	try: 
		wait_and_find_element(webdriver, "//form[@class='attachmentForm']//input[@type='submit']", 5).click()
	except:
		print "Could not click on the Post button"
Exemple #31
0
 def wait_for_element(self, webdriver, path):
     limit = 1800  # waiting limit in seconds
     inc = 0.5  # in seconds; sleep for 500ms
     c = 0
     while (c < limit):
         try:
             print "Waiting... " + str(c)
             webdriver.find_element_by_xpath(path)
             print "Found!"
             return 1
         except Exception:  # the most diabolical python antipattern
             time.sleep(inc)
             c = c + inc
     print "The element hasn't been found."
Exemple #32
0
 def hashtagComment(self, commentPercentage):
     sleep(random.uniform(.5, 1))
     commentButton = webdriver.find_element_by_xpath(
         '/html/body/div[4]/div[2]/div/article/div[2]/section[1]/span[2]/button'
     )
     if (random.randint(0, 100) < int(commentPercentage)):
         commentInput = webdriver.find_element_by_xpath(
             '/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/textarea'
         )
         commentInput.send_keys('THAT LOOKS AMAZIN!!')
         postButton = webdriver.find_element_by_xpath(
             '/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/button'
         )
         postButton.click()
def transform_markdown_towechat(webdriver, content):
    webdriver.get('http://blog.didispace.com/tools/online-markdown/')
    content_input = webdriver.find_element_by_xpath('//*[@id="input"]')
    content_input.clear()
    content = content.replace('"',
                              '\\"').replace('\n', (' \\' + 'n ')).replace(
                                  '\\"\\n\\"', '\\"\\\\n\\"')
    # content = 'hello' + ' \\' + 'n' + '\\ ' + 'world'
    dd = "arguments[0].value=\"%s\"" % content
    print('content is ' + dd)
    webdriver.execute_script(dd, content_input)
    copy_btn = webdriver.find_element_by_xpath(
        '//*[@id="output"]/div[2]/button')
    copy_btn.click()
Exemple #34
0
def url_smartclick(webdriver, url):
    '''
    Helps navigate around web elements that like to crash the scraper.
    Attempts to click normally, and if the element is not in view it will force
    the element into view, allowing it to be clicked.
    
    --------------------------------------------------------------------------------------------
    Input:
    webdriver: Selenium webdriver object
    url: Selenium "child" object, points to page you are currently on.
    --------------------------------------------------------------------------------------------
    Output:
    NA: Function is for navigation, not returning values.
    '''
	try:
		url.find_element_by_xpath(".//div[@class='indicator']").click()
		print("url_smartclick," " 1")
	except:
		print("url_smartclick," " 2")
		temp = webdriver.find_element_by_xpath('//div[@class="designers-popover"]')
		temp = temp.find_element_by_xpath('.//div[@class="content"]')
		temp_designers = temp.find_elements_by_xpath('.//div[@class="active-indicator"]')
		webdriver.execute_script("arguments[0].scrollIntoView();", temp_desingers[-1])
		#ActionChains(webdriver).move_to_element(temp_designers[-1])
		url.find_element_by_xpath(".//div[@class='indicator']").click()
Exemple #35
0
def getMaxAmount():
    txt = webdriver.find_element_by_xpath(
        '/html/body/div[1]/div/main/div/div/div/div[2]/div[2]/div[2]/div/div[3]/div[1]/form/div[1]/div/div'
    ).text
    lst = txt.split(' ')
    amnt = lst[1]
    return amnt
Exemple #36
0
def probe_generator(webdriver):
	# <meta name="generator" content="WordPress 4.1.1" />
	try:
		metatag = webdriver.find_element_by_xpath("//meta[@name='generator']")
		data = metatag.get_attribute("content")
		print "Generator: "+data
	except:
		pass
Exemple #37
0
def probe_wordpress(webdriver):
	# <meta name="generator" content="WordPress 4.1.1" />
	try:
		metatag = webdriver.find_element_by_xpath("//meta[@name='generator']")
		data = metatag.get_attribute("content")
		if 'WordPress' in data:
			print "WordPress CMS detected"
	except:
		pass
def IsElementPresent(webdriver):
    try:
        webdriver.find_element_by_xpath("/html/body/form/div[3]/main/section/div/section/div/section/div/div[1]/div/div/div/div[8]/div/div/strong/p/label")
        return True
    except:
        return False
Exemple #39
0
def logOut(webdriver):
	webdriver.find_element_by_xpath("//div[@class='menuPulldown']").click()
	wait_and_find_element(webdriver, "//form[@id='logout_form']//input[@type='submit']", 2).click()
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()
Exemple #41
0
def check_exists_by_xpath(xpath):
    try:
        webdriver.find_element_by_xpath(xpath)
    except NoSuchElementException:
        return False
    return True