Created
April 4, 2016 20:50
-
-
Save rakeshsukla53/818920a1fb5826b407b70ad72ecc50aa to your computer and use it in GitHub Desktop.
donald trump quotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from brain_quote_page import BrainQuotePage | |
import csv | |
browser = webdriver.Firefox() | |
type(browser) | |
browser.get('http://www.brainyquote.com/quotes/authors/d/donald_trump.html') | |
data = [] | |
while True: | |
try: | |
all_quotes = browser.find_elements_by_css_selector(BrainQuotePage.donald_trump_quotes) | |
all_quote_links = browser.find_elements_by_css_selector(BrainQuotePage.donald_trump_links) | |
for quotes, quote_link in zip(all_quotes, all_quote_links): | |
quotes = (quotes.text, quote_link.get_attribute('href')) | |
data.append(quotes) | |
next_page = browser.find_element_by_css_selector(BrainQuotePage.donald_trump_next_page) | |
next_page.click() | |
except: | |
break | |
headers = ('Donald Trump', 'Quotes') | |
with open('write_data_1.csv', 'w+') as data_file: | |
writer = csv.writer(data_file) | |
writer.writerow(headers) | |
writer.writerows(data) | |
browser.quit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment