Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created April 26, 2020 03:25
Show Gist options
  • Save havenwood/beeaa6bbdf8c3312473feba7376267b3 to your computer and use it in GitHub Desktop.
Save havenwood/beeaa6bbdf8c3312473feba7376267b3 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
url = 'https://www.cnbc.com/2020/04/25/coronavirus-uk-prime-minister-boris-johnson-will-return-to-work-monday.html'
html = Nokogiri::HTML open(url, &:read)
xpath_query = '//*[@id="RegularArticle-KeyPoints-4"]/div/div[2]/div/div/ul/li[1]/text()'
html.xpath(xpath_query).text
#=> "Johnson has been convalescing at Chequers, the prime minister's country estate, since he was discharged from hospital earlier this month. "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment