Skip to content

Instantly share code, notes, and snippets.

@edlvj
Created January 7, 2017 13:09
Show Gist options
  • Save edlvj/9aab67185c17d623c55d6086fbc0ade8 to your computer and use it in GitHub Desktop.
Save edlvj/9aab67185c17d623c55d6086fbc0ade8 to your computer and use it in GitHub Desktop.
require 'mechanize'
mechanize = Mechanize.new
page = mechanize.get('https://www.safaribooksonline.com/accounts/login/')
form = page.forms.first
form['email'] = 'your mail'
form['password1'] = 'your pass'
page = form.submit
for i in 1..82
if i.between?(1, 9)
page_book_url = mechanize.get("https://www.safaribooksonline.com/library/view/learn-game-programming/9781680501537/f_000#{i}.html")
elsif i.between?(10,82)
page_book_url = mechanize.get("https://www.safaribooksonline.com/library/view/learn-game-programming/9781680501537/f_00#{i}.html")
end
text = page_book_url.search("#sbo-rt-content")
File.open("ruby_game/page_#{i}.html", "w") {|f| f.write("<head><meta charset=utf-8></head>\n" + text) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment