import sys
import httplib

showlines 
= 100
try:
    servername, filename 
= sys.argv[1:]           # cmdline 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 received
    data = file.readlines()
    file.close()                                  
# show lines with eoln at end

    
if len(data) < showlines:
        showlines 
= len(data)

    
for line in data[:showlines]: print line,       # to save, write data to file

相关文章:

  • 2021-11-23
  • 2021-09-11
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
猜你喜欢
  • 2021-09-24
  • 2021-11-12
  • 2022-12-23
  • 2021-07-30
  • 2021-11-18
  • 2021-08-07
相关资源
相似解决方案