Skip to content

Instantly share code, notes, and snippets.

@issyl0
Created December 14, 2015 19:01
Show Gist options
  • Save issyl0/3b44302cb34b1c00a507 to your computer and use it in GitHub Desktop.
Save issyl0/3b44302cb34b1c00a507 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
require 'net/http'
# Get the video title from each of the Delta Tube videos, if they exist.
(1..5000).each do |id|
url = URI.parse("http://www.delta-tube.com/video/#{id}")
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)
if res.code == 200
get_title(id,url)
else
# Go to the next `id` and do it all again.
end
end
def get_title(id,url)
puts id + "," + Nokogiri::HTML(open(url)).xpath('//*[@id="mainContent"]/div[1]/div/h1').to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment