Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. tArgs = {...}
  2. if #tArgs < 1 then
  3.   print('Usage: print_urls <url>')
  4.   return
  5. end
  6.  
  7. url = tArgs[1]
  8.  
  9. page = http.get(url)
  10. h = html.parsestr(page.readAll())
  11. root = h
  12.  
  13. function search(obj)
  14.   local res = {}
  15.   if type(obj) == 'table' then
  16.     if(obj._tag and (obj._tag == 'a') ) then
  17.       if type(obj[1]) == 'string' then
  18.         table.insert(res, {obj[1], obj._attr.href})
  19.       end
  20.     else
  21.       for i,v in ipairs(obj) do
  22.         local res2 = search(v)
  23.         for j,w in ipairs(res2) do
  24.           table.insert(res, w)
  25.         end
  26.       end
  27.     end
  28.   end
  29.   return res
  30. end
  31.  
  32. local urls = search(root)
  33. textutils.tabulate( unpack(urls) )