Advertisement
An_random_user

dl-htmlparser-cc

Jun 28th, 2024 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. function get( sUrl )
  2. write( "Connecting to " .. sUrl .. "... " )
  3.  
  4. local ok, err = http.checkURL( sUrl )
  5. if not ok then
  6. print( "Failed." )
  7. if err then
  8. printError( err )
  9. end
  10. return nil
  11. end
  12.  
  13. local response = http.get( sUrl , nil , true )
  14. if not response then
  15. print( "Failed." )
  16. return nil
  17. end
  18.  
  19. print( "Success." )
  20.  
  21. local sResponse = response.readAll()
  22. response.close()
  23. return sResponse
  24. end
  25.  
  26. function download( sURL,sFile ) -- Download file
  27. local sUrl = sURL -- Alias
  28. local sPath = shell.resolve( sFile )
  29. if fs.exists( sPath ) then
  30. print( "File already exists" )
  31. return
  32. end
  33.  
  34. -- Do the get
  35. local res = get( sUrl )
  36. if res then
  37. local file = fs.open( sPath, "wb" )
  38. file.write( res )
  39. file.close()
  40.  
  41. print( "Downloaded as "..sFile )
  42. end
  43. end
  44. download("https://raw.githubusercontent.com/msva/lua-htmlparser/master/src/htmlparser.lua","htmlparser.lua")
  45. fs.makeDir("htmlparser")
  46. download("https://raw.githubusercontent.com/msva/lua-htmlparser/master/src/htmlparser/voidelements.lua","htmlparser/voidelements.lua")
  47. download("https://raw.githubusercontent.com/msva/lua-htmlparser/master/src/htmlparser/ElementNode.lua","htmlparser/ElementNode.lua")
  48. print("Done")
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement