Exemplo n.º 1
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
Exemplo n.º 2
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>>>>>>>>>>>>>>')
Exemplo n.º 3
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()