Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import the necessary modules
- require 'nokogiri'
- require 'open-uri'
- begin
- # make the GET request and retrieve the HTML content
- html_content = URI.open('https://www.scrapingcourse.com/ecommerce/').read
- # load HTML document
- doc = Nokogiri::HTML(html_content)
- # select the first product title
- first_product_title = doc.at_css('h2')
- puts first_product_title.text
- rescue OpenURI::HTTPError => e
- puts "An error occurred: #{e.message}"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement