Created
December 14, 2015 19:01
-
-
Save issyl0/3b44302cb34b1c00a507 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. | |
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