-
-
Save 46bit/be0737ac2bb4758c554c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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. | |
next | |
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