Пример #1
0
    def send_form(self, address, price, link):
        driver.get(DOCS_LINK)
        driver.maximize_window()
        sleep(2)
        address_input = driver.find_element_by_xpath(
            '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div'
            '[1]/div/div[1]/input')
        price_input = driver.find_element_by_xpath(
            '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div'
            '[1]/div/div[1]/input')
        link_input = driver.find_element_by_xpath(
            '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[3]/div/div/div[2]/div/div[1]'
            '/div/div[1]/input')
        send_button = driver.find_element_by_xpath(
            '//*[@id="mG61Hd"]/div[2]/div/div[3]/div[1]/div/div/span')

        address_input.send_keys(address)
        price_input.send_keys(price)
        link_input.send_keys(link)
        send_button.click()
        sleep(2)
        driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')
        driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL +
                                                          Keys.TAB)
        driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')
def login():
    # navigate to the application home page
    driver.get("https://www.mercadona.es/ns/entrada.php?js=1")
    username = driver.find_element_by_id("username")
    username.clear()
    username.send_keys(config["username"])
    password = driver.find_element_by_id("password")
    password.clear()
    password.send_keys(config["password"])
    username.submit()
    time.sleep(1)
    try:
        alert = driver.switch_to_alert().text
        return False
    except NoAlertPresentException:
        return True
Пример #3
0
def get_daily_reading(user_command):
    # horoscope.com's order of the zodiac sign
    sign_order = {
        'aries': '1',
        'taurus': '2',
        'gemini': '3',
        'cancer': '4',
        'leo': '5',
        'virgo': '6',
        'libra': '7',
        'scorpio': '8',
        'sagittarius': '9',
        'capricorn': '10',
        'aquarius': '11',
        'pisces': '12'
    }

    sign = user_command.split(' ')[0].lower()
    current_date = str(date.today())

    # check if daily reading already exists
    if get_stored_daily_readings(sign, current_date):
        stored_reading = get_stored_daily_readings(sign, current_date)
        return stored_reading

    # web scraping daily reading from horoscope.com
    url = 'https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx?sign='
    sign_url = url + sign_order[sign]
    driver.get(sign_url)
    soup = BeautifulSoup(driver.page_source, "lxml")
    driver.close()
    p_tags = soup.find(class_='main-horoscope').find_all('p')
    # may need to change
    horoscope = str(p_tags[0])[35:-4]

    # store daily reading in json file
    store_daily_readings(sign, current_date, horoscope)

    return horoscope
Пример #4
0
def get_quotes(url):
    try:
        # implicitly_wait tells the driver to wait before throwing an exception
        driver.implicitly_wait(30)
        # driver.get(url) opens the page
        driver.get(url)
        # This starts the scrolling by passing the driver and a timeout
        scroll(driver, 5)
        # Once scroll returns bs4 parsers the page_source
        soup = BeautifulSoup(driver.page_source, "lxml")
        # Them we close the driver as soup_a is storing the page source
        driver.close()

        # Empty array to store the links
        quotes = []

        regex_quotes = re.compile('^b-qt')
        regex_authors = re.compile('^bq-aut')

        quotes_list = soup.find_all('a', attrs={'class': regex_quotes})
        authors_list = soup.find_all('a', attrs={'class': regex_authors})

        quotes = []
        zipped_quotes = list(zip(quotes_list, authors_list))
        for i, x in enumerate(zipped_quotes):
            quote = x[0]
            author = x[1]
            quotes.append({
                "id": f"id-{i}",
                "quote": quote.get_text(),
                "author": author.get_text(),
                "author-link": author.get('href')
            })

        with open("quotes.json", 'w') as json_file:
            json.dump(quotes, json_file)
    except Exception as e:
        print(e, '>>>>>>>>>>>>>>>Exception>>>>>>>>>>>>>>')
Пример #5
0
def get_comments(url, id):
    try:
        driver.implicitly_wait(30)
        driver.get(url)
        soup = BeautifulSoup(driver.page_source, "lxml")

        comm_list = []
        comments_list = soup.find_all('div', attrs={'class': "narrow"})
        for i, x in enumerate(comments_list):
            # remove blockquote tag and its content.
            if x.blockquote:
                x.blockquote.decompose()
            comm_list.append({
                "id": f"id-{i}",
                "comment": x.get_text(separator='\n')
            })

            # write the comment into json file.
            with open(output_file_path + "comments" + str(id) + ".json",
                      "w") as json_file:
                json.dump(comm_list, json_file, indent=0)
    except Exception as e:
        print(e, ">>>>>>>>>>>>>Exception>>>>>>>>>>>>>")
Пример #6
0
from selenium_driver import driver
from selenium.common.exceptions import NoSuchElementException
from time import sleep
from data import url, email, password, job_title, job_location

# Gets inside LinkedIn
driver.get(url)
sleep(0.5)

# Accepting cookies
driver.find_element_by_xpath(
    '//*[@id="artdeco-global-alert-container"]/div[1]/section/div/div[2]/button[2]'
).click()
sleep(0.5)
# Clicks login button
click_login_button = driver.find_element_by_xpath(
    '/html/body/nav/div/a[2]').click()

# Finds email and password input fields and it sends the respective
email_input = driver.find_element_by_id('username')
email_input.send_keys(email)
sleep(0.5)

password_input = driver.find_element_by_id('password')
password_input.send_keys(password)
sleep(0.5)

driver.find_element_by_xpath(
    '//*[@id="organic-div"]/form/div[3]/button').click()
sleep(3)
Пример #7
0
from selenium_driver import driver
from time import time, sleep

cookie_clicker_game_url = 'http://orteil.dashnet.org/experiments/cookie/'
driver.get(cookie_clicker_game_url)

initial_store = driver.find_elements_by_class_name('grayed')
cookie_object = driver.find_element_by_id('cookie')

initial_time = time()
while True:
    current_time = time()
    new_store = driver.find_elements_by_class_name('grayed')
    cookie_object.click()

    if current_time - initial_time > 5 and len(initial_store) != len(
            new_store):
        index_to_pick = (len(initial_store) - len(new_store)) - 1
        click_item = initial_store[index_to_pick].click()
        sleep(1)
        initial_time = current_time
        initial_store = new_store
Пример #8
0
from selenium_driver import driver
from selenium.webdriver.common.keys import Keys

wikipedia_mainpage_url = 'https://en.wikipedia.org/wiki/Main_Page'
app_brewery_newsletter = 'http://secure-retreat-92358.herokuapp.com/'

# driver.get(wikipedia_mainpage_url)

# articles_in_eng = driver.find_element_by_css_selector('#articlecount a:first-child')
# articles_in_eng.click()

# search_input = driver.find_element_by_name('search')
# search_input.send_keys('JavaScript')
# search_input.send_keys(Keys.ENTER)

driver.get(app_brewery_newsletter)

first_name = driver.find_element_by_name('fName')
first_name.send_keys('Binay')
last_name = driver.find_element_by_name('lName')
last_name.send_keys('Python Dev ;)')
email = driver.find_element_by_name('email')
email.send_keys('*****@*****.**')
email.send_keys(Keys.ENTER)

# driver.close()
Пример #9
0
from selenium_driver import driver
amazon_url = 'https://www.amazon.es/Huawei-Matebook-D15-Multi-Screen-Collaboration/dp/B083V6LT1T/ref=pd_day0_2?pd_rd_w' \
             '=PD3a8&pf_rd_p=0ff21a3e-4297-4047-87ec-ba06b6bc995e&pf_rd_r=K80J9VPE80R3PTN64J0G&pd_rd_r=9d94802a-885f-4' \
             'b9e-8935-1672639d291a&pd_rd_wg=tkcrg&pd_rd_i=B083V6LT1T&psc=1'

driver.get(amazon_url)
deal_price = driver.find_element_by_id('priceblock_ourprice')
print(deal_price.text)

driver.close()
Пример #10
0
from selenium_driver import driver
from pprint import pprint

python_org_url = 'https://www.python.org/'
driver.get(python_org_url)
list_elements = driver.find_elements_by_css_selector('.blog-widget ul.menu li')

list_of_events = {}
for index, val in enumerate(list_elements):
    date = val.find_element_by_css_selector('time')
    title = val.find_elements_by_css_selector('a')
    list_of_events[index] = {'time': date.text, 'name': title[0].text}

pprint(list_of_events)

driver.close()
Пример #11
0
from selenium_driver import driver
from bs4 import BeautifulSoup
import random as r

quote_list = []
author_list = []

driver.get("https://www.brainyquote.com/quote_of_the_day")

content = driver.page_source
soup = BeautifulSoup(content, features='html.parser')

for i in soup.findAll('div', attrs={'class': 'qotd-q-cntr'}):
    temp_quote = i.find('a', attrs={'title': 'view quote'})
    temp_author = i.find('a', attrs={'title': 'view author'})
    quote_list.append(temp_quote.text)
    author_list.append(temp_author.text)

print(quote_list)
index = r.randint(0, int(len(quote_list)))
quote = quote_list[index]
author = author_list[index]
Пример #12
0
from selenium_driver import driver
from fetch_quote import quote, author
import time
import datetime as dt

driver.get(
    'https://quotescover.com/designs/wording?res=UFg2ajdxa2FRQ3hIa0VrZGc5dEE0Zz09'
)
driver.find_element_by_id("quotes").send_keys(quote)
driver.find_element_by_id("author").send_keys(author)
driver.find_element_by_id("template-contactform-submit").click()

time.sleep(3)

driver.find_element_by_xpath(
    "//div[@class='forDesktop']/div/button[@onclick='openDownload()']").click(
    )

time.sleep(15)

driver.find_element_by_xpath('''//button[@onclick="openNav('jpg')"]''').click()

time.sleep(3)

now = dt.datetime.now()
fileName = "quote_" + now.strftime("%d_%H_%M_%S")
driver.find_element_by_id("fileName").send_keys(fileName)

time.sleep(3)

driver.find_element_by_xpath(