Last active
March 18, 2017 01:46
-
-
Save bnymn/7c34a49660be4755094286e0da5a8546 to your computer and use it in GitHub Desktop.
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
loop do | |
# Wait browser to load | |
loop do | |
sleep(2) | |
if driver.execute_script('return document.readyState') == "complete" | |
break | |
end | |
end | |
# Load page | |
doc = Nokogiri::HTML(driver.page_source); | |
companies = doc.css("div.results > div[data-_tn='companies/row']"); | |
if companies.count > 0 | |
# Print companies | |
companies.each do |company| | |
# This ID is unique! | |
name_a = company.css("div.startup > div.company div.name a"); | |
if name_a && !name_a.empty? | |
id = company.css("div.startup > div.company div.name a").attr('data-id').text; | |
else | |
next | |
end | |
name = company.css("div.startup > div.company div.name").text.strip! | |
pitch = company.css("div.startup > div.company div.pitch").text.strip! | |
puts "id: #{id}" | |
puts "name: #{name}" | |
puts "pitch: #{pitch}" | |
puts "==" | |
end | |
# Remove old companies | |
script = "$(\"div.results > div[data-_tn='companies/row']\").remove();" | |
driver.execute_script(script); | |
# Load new companies | |
if browser.has_css?('.more') | |
browser.find('.more').click | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment