Skip to content

Instantly share code, notes, and snippets.

@rakeshsukla53
Created April 4, 2016 20:50
Show Gist options
  • Save rakeshsukla53/818920a1fb5826b407b70ad72ecc50aa to your computer and use it in GitHub Desktop.
Save rakeshsukla53/818920a1fb5826b407b70ad72ecc50aa to your computer and use it in GitHub Desktop.
donald trump quotes
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