Created
July 17, 2023 17:47
-
-
Save LevitatingBusinessMan/d95e8964a828809049814b66fce8fa0f to your computer and use it in GitHub Desktop.
Hacker News one-liner scraper. Run with `ruby -rnet/http -rnokogiri hn.rb`
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
| File.write 'hn.csv', Nokogiri(Net::HTTP.get(URI('https://news.ycombinator.com'))).css('.titleline > a', '.subline').each_slice(30).to_a.transpose.map {|a,l|[a.text, a.attr('href'), l.css('.score').first.text.chomp(' points').to_i, l.css('.hnuser').first.text, l.css('.age').first.attr('title')].to_csv}.join |
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
| pp Nokogiri(Net::HTTP.get(URI('https://news.ycombinator.com'))).css('.titleline > a','.subline').each_slice(30).to_a.transpose.map{|a,l|[a.text,a.attr('href'),l.css('.score').first.text.chomp(' points').to_i,l.css('.hnuser').first.text, l.css('.age').first.attr('title')]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment