Advertisement
dereksir

Untitled

Jun 6th, 2024 (edited)
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.46 KB | None | 0 0
  1. # import the necessary modules
  2. require 'nokogiri'
  3. require 'open-uri'
  4.  
  5. begin
  6.   # make the GET request and retrieve the HTML content
  7.   html_content = URI.open('https://www.scrapingcourse.com/ecommerce/').read
  8.  
  9.   # load HTML document
  10.   doc = Nokogiri::HTML(html_content)
  11.  
  12.   # select the first product title
  13.   first_product_title = doc.at_css('h2')
  14.   puts first_product_title.text
  15.  
  16. rescue OpenURI::HTTPError => e
  17.   puts "An error occurred: #{e.message}"
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement