[#] Biblioteka httplib w skryptach Pythona

( Ostatnio zmieniony pt., 04/07/2008 - 12:29 )
 

get_page.py

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import httplib
import sys

def get_page(host,port,url):
    h = httplib.HTTP(host, port)
    h.putrequest('GET', url)
    h.putheader('Host', host)
    h.putheader('User-agent', 'python-httplib')
    h.endheaders()

    (returncode, returnmsg, headers) = h.getreply()
    if returncode != 200:
        print returncode, returnmsg
        sys.exit()

    f = h.getfile()
    return f.read()

if __name__ == '__main__':
  site = get_page("ni.imasters.pl", 80, "/index.php")
  print site

  sys.exit()
5
Twoja ocena: Brak Średnio: 5 (2 głosy)