ImportSys
ImportHttplib
Showlines = 100
Try :
Servername, filename = SYS. argv [ 1 :] # Using line ARGs?
Except :
Servername, filename = ' Www.testinside.com ' , ' /Index.html '
Print Servername, filename
Server = Httplib. HTTP (servername) # Connect to HTTP site/Server
Server. putrequest ( ' Get ' , Filename) # Send request and headers
Server. putheader ( ' Accept ' , ' Text/html ' ) # POST requests work here too
Server. endheaders () # As do CGI script filenames
Errcode, errmsh, replyheader = Server. getreply () # Read reply info Headers
If Errcode ! = 200 : # 200 means success
Print ' Error sending request ' , Errcode
Else :
File = Server. GetFile () # File OBJ for data stored ed
Data = File. readlines ()
File. Close () # Show lines with eoln at end
If Len (data) < Showlines:
Showlines = Len (data)
ForLineInData [: showlines]:PrintLine,#To save, write data to file