Sha256: 2f12746ab3f266d0f9adb0f1b7dedc62ba64739bbff1b2ebf7384deb1d92d310
Contents?: true
Size: 1.2 KB
Versions: 10
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 MyCongress.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
10 entries across 10 versions & 1 rubygems