Ejemplo n.º 1
0
def mailru_collector():
    driver = Safari()
    driver.maximize_window()
    db = client['Sends_from_mailru']
    sends_in_db = db.sends_in_db

    driver.get('https://mail.ru')

    elem = driver.find_element_by_id('mailbox:login-input')
    elem.send_keys(get_login())
    elem.submit()

    elem = WebDriverWait(driver, 10).until(
        EC.visibility_of(driver.find_element_by_id('mailbox:password-input')))
    elem.send_keys(get_password())
    elem.submit()

    WebDriverWait(driver, 10).until(EC.title_contains('- Почта Mail.ru'))

    sends_block = driver.find_element_by_xpath(
        "//div[@class='dataset__items']")
    sends = set()
    while True:
        len_of_sends_list = len(sends)
        list_sends = sends_block.find_elements_by_xpath(".//a[@href]")
        for send in list_sends:
            sends.add(send.get_attribute('href'))
        if len(sends) == len_of_sends_list:
            break

        var = list_sends[-1].location_once_scrolled_into_view
        time.sleep(1)

    while sends:
        send_dict = {}
        send_url = sends.pop()
        driver.get(send_url)

        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//div[@class='letter-body']")))

        text_send = driver.find_element_by_xpath(
            "//div[contains(@class, 'letter-body')]").text
        title_send = driver.find_element_by_tag_name('h2').text
        from_send = driver.find_element_by_class_name('letter-contact').text
        date_send = driver.find_element_by_class_name('letter__date').text

        send_dict['text'] = text_send
        send_dict['title'] = title_send
        send_dict['from'] = from_send
        send_dict['date'] = date_send
        send_dict['url'] = send_url

        sends_in_db.update_one({'url': send_url}, {'$set': send_dict},
                               upsert=True)

    driver.close()
from selenium.webdriver import Safari

b = Safari()
b.get('http://google.com')
e = b.find_element_by_id('lst-ib')

e.click()  # is optional, but makes sure the focus is on editbox.
e.send_keys('12.34')
e.get_attribute('value')
# outputs: u'12.34'

e.click()
e.clear()
e.get_attribute('value')
# outputs: u''

e.send_keys('56.78')
e.get_attribute('value')
# outputs: u'56.78'
Ejemplo n.º 3
0
# importing selenium libararies
from selenium.webdriver import Safari
#import selenium libraray to amke keys working through
#automation
from selenium.webdriver.common.keys import Keys
# calling the web driver of safari
driver = Safari()
#taking user id and passowrd input from the user
# you can hard code this if you want to save
# this file locallly on your computer
user1 = input("enter your user id for moddle :")
passw1 = input("enter your password :"******"https://moodle.iitd.ac.in/login/index.php")
# finding the user id and password elements on the login page
user = driver.find_element_by_id("username")
passw = driver.find_element_by_id("password")
# entering the user id and pasword in the form
user.send_keys(user1)
passw.send_keys(passw1)
# finding the capthca input in the login page
captcha = driver.find_element_by_id("valuepkg3")
# making a local copy of the login form so that
# captcha can be extracted and solved
text1 = driver.find_element_by_id("login").text
# figuring out which type of capthca is asked
case1 = text1[326:329]  # for add or sub
case2 = text1[332:335]  # for first or second value


def checking_the_type_of_captha(case1, case2):