Created
September 20, 2023 22:24
-
-
Save hilmanski/ebff52f14e5662481788814095e3eb77 to your computer and use it in GitHub Desktop.
Simple example web scraping with Ruby for beginner
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
require 'net/http' | |
require 'nokogiri' | |
# HTTP Client | |
url = 'https://www.w3schools.com' | |
response = Net::HTTP.get_response(URI(url)) | |
if response.code != "200" | |
puts "Error: #{response.code}" | |
exit | |
end | |
# HTML Parser | |
doc = Nokogiri::HTML(response.body) | |
doc.css('#subtopnav a').each do |node| | |
print(node.content + "\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Text explanation: web Scraping with Ruby for beginner