Skip to content

Instantly share code, notes, and snippets.

@ThomasWitte
Created October 17, 2015 16:59
Show Gist options
  • Save ThomasWitte/a2c5668e1158629d209d to your computer and use it in GitHub Desktop.
Save ThomasWitte/a2c5668e1158629d209d to your computer and use it in GitHub Desktop.
small script to download webcomics
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