Created
July 22, 2013 08:13
-
-
Save kovacshuni/6052151 to your computer and use it in GitHub Desktop.
Sanity check of video.ft.com
This file contains 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 'net/http' | |
def fetch(uri_str, limit = 10) | |
raise ArgumentError, 'too many HTTP redirects' if limit == 0 | |
response = Net::HTTP.get_response(URI(uri_str)) | |
case response | |
when Net::HTTPSuccess then | |
response.body()[/<span class="video\-length">\s*(\d+:\d+ min)\s*<\/span>/] | |
when Net::HTTPRedirection then | |
location = response['location'] | |
warn "redirected to #{location}" | |
fetch(location, limit - 1) | |
else | |
response.value | |
end | |
end | |
print fetch('http://video.ft.com') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment