Created
October 17, 2015 16:59
-
-
Save ThomasWitte/a2c5668e1158629d209d to your computer and use it in GitHub Desktop.
small script to download webcomics
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
local start_url = 'http://www.atomic-robo.com/atomicrobo/v1ch1-cover' | |
local next_page_pattern = '<a href="([^"]+)" class="next" rel="next"></a>' | |
local last_page_pattern = '<a href="([^"]+)" class="last" rel="index"></a>' | |
local image_pattern = '<img title="([^"]+)" src="([^"]+)" id="cc-c' | |
local http = require('socket.http') | |
local page_url = start_url | |
local count = 0 | |
while not exit do | |
local page, code = http.request(page_url) | |
if code ~= 200 then | |
print('downloading page failed with code ' .. code) | |
exit = true | |
end | |
page_url = string.match(page, next_page_pattern) | |
title, image_url = string.match(page, image_pattern) | |
--print(string.format('curl -s %s > "%04d - %s.jpg"', image_url, count, title)) | |
os.execute(string.format('curl -s %s > "%04d - %s.jpg"', image_url, count, title)) | |
count = count + 1 | |
print('Downloaded ' .. image_url) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment