import urllib.request
def countHead(url):
page = urllib.request.urlopen(url)
numHeadLines = 0
line = page.readline().decode('utf-8')
while '' not in line:
line = page.readline().decode('utf-8')
line = page.readline().decode('utf-8')
while '' not in line:
numHeadLines = numHeadLines + 1
line = page.readline().decode('utf-8')
line = page.readline().decode('utf-8')
while "" not in line:
line = page.readline().decode('utf-8')
line = page.readline().decode('utf-8')
while line != "" and "" not in line:
print (line[:-1])
line = page.readline().decode('utf-8')
print ("number of lines in header = ", numHeadLines)
page.close()
url = "http://people.cornellcollege.edu/tdelaubenfels/home.htm"
countHead(url)