Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function generatePath(subreddit)
- if type(subreddit) ~= "string" then subreddit = "*" end
- return "https://archive.is/http:reddit.com/r/"..subreddit.."/comments/*"
- end
- local function getLinks(path,archive_links,completed_paths,verbose)
- local request = http.get(path)
- if verbose then print(path) end
- if not request then return archive_links end
- local html = request.readAll()
- request.close()
- if type(archive_links) ~= "table" then archive_links = {} end
- if type(completed_paths) ~= "table" then completed_paths = {} end
- completed_paths[path] = true
- for str in string.gmatch(html,"href=\"[%w%p]+\"") do
- local link = str:sub(7,-2)
- if string.match(link,"^https://archive%.is/%w%w%w%w%w$") then
- table.insert(archive_links,link)
- elseif string.match(link,"https://archive%.is/offset=%d%d") then
- if not completed_paths[link] then
- getLinks(link,archive_links,completed_paths,verbose)
- end
- end
- end
- return archive_links
- end
- local links = getLinks(generatePath("politics"))
- print(textutils.serialise(links),#links)
Advertisement
Add Comment
Please, Sign In to add comment