Sha256: c31bc859b01bd347117ee5c4f84b6e940f60cac3581a782104a89b7d6f3ad835
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
class SeleniumScraper def initialize(site, state) # Launch Chrome behind the scenes & scrape website options = Selenium::WebDriver::Chrome::Options.new(args: ['headless']) driver = Selenium::WebDriver.for(:chrome, options: options) driver.get(site) # grab relevant section from website info = driver.find_elements(css: 'div.row.oa-elected-official-group-list-item') #Error for not locating address / invalid address if info[3] == nil puts " " puts "Could not locate address. Press 'Enter' to return to Main Menu.".colorize(:blue) nothing = gets.chomp MCongress.new.call end # Once Selenium passes the refresh, Nokogiri is easier # to target the actual elements we need elements = Nokogiri::HTML(open(driver.current_url)) # Grab two senators and representative sen1 = info[3].text.split("\n") sen2 = info[4].text.split("\n") rep = info[5].text.split("\n") driver.quit # Sent to FindRepresentatives method to organize info for display FindRepresentatives.new(sen1, sen2, rep, elements, state) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
my-congress-0.2.2 | lib/selenium_scraper.rb |
my-congress-0.2.1 | lib/selenium_scraper.rb |