Created
April 8, 2014 04:45
-
-
Save marcus/10091836 to your computer and use it in GitHub Desktop.
Get the publication date for a bunch of books
This file contains hidden or 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
require "selenium-webdriver" | |
books = [ | |
["One Hundred Years of Solitude", "Marquez"], | |
["Love in the Time of Cholera", "Marquez"], | |
["Sons and Lovers", "D.H. Lawrence"], | |
["Lady Chatterley's Lover", "D.H. Lawrence"], | |
["Sound and Fury", "Faulkner"], | |
["Grapes of Wrath","Steinbeck"], | |
["Tender Is The Night","Fitzgerald"], | |
["Rabbit Run","Updike"], | |
["Angle of Repose","Stegnar"], | |
["Waiting for Godot","Beckett"], | |
["As I Lay Dying","Faulkner"], | |
["Point Counterpoint","Huxley"], | |
["To the Lighthouse","Woolf"], | |
["House of the Dead","Dostoyevsky"], | |
["I, Claudius","Graves"], | |
["Go Tell It On The Mountain","Baldwin"], | |
["First Circle","Solzhenitsyn"], | |
["The Sun Also Rises","Hemmingway"], | |
["The Trial","Kafka"], | |
["On The Road","Kerouac"], | |
["Death Comes For The Archbishop","Cather"], | |
["Speak, Memory","Nabokov"], | |
["Ulysses","Joyce"], | |
["Finnegan's Wake","Joyce"], | |
["Nostramo","Conrad"], | |
["Kim","Kipling"], | |
["Gulliver's Travels","Swift"], | |
["Lord Jim","Conrad"], | |
["Midnight's Children","Rushdie"], | |
["Death Of A Salesman","Miller"], | |
["The Invisible Man","Elison"], | |
["Gypsy Ballads","Lorca"], | |
["Dead Souls","Gogol"], | |
["All Quiet on the Western Front","Remarque"], | |
["Tortilla Flat","Steinbeck"], | |
["The Red And The Black","Stendhal"], | |
["The Jungle","Sinclair"], | |
["The Death of Ivan Illyich","Tolstoy"] | |
] | |
final_results = [] | |
driver = Selenium::WebDriver.for(:chrome) | |
#driver = Selenium::WebDriver.for(:firefox) | |
#driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:3333") | |
books.each do |title, author| | |
driver.navigate.to "https://www.google.com/search?q=#{title.split.join("+")}+published" | |
e = driver.find_element :css, '.vk_ans' | |
begin | |
year = e.text | |
year = year.match(/(\d\d\d+)/) | |
puts "Got year for #{title} - #{year}" | |
rescue Selenium::WebDriver::Error::WebDriverError | |
year = "-" | |
puts "#{title} Failed." | |
end | |
final_results.push [year, title, author] | |
sleep(1) | |
end | |
driver.quit | |
puts final_results | |
puts final_results.map{|fr| fr[0]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment