nick34992
2/16/2017 - 2:57 AM

Python Module: urllib: readline URL

Python Module: urllib: readline URL

#!/usr/bin/env python3
'''Prints first line of HTML markup.
Enter following example on unix-like command line:
./read_first_line.py http://play.typeracer.com/
Command line expects URL.

If encountering the following error message:
bash: ./read_first_line.py: Permission denied
Adjust permissions.
'''

import sys
from urllib.request import urlopen

try:
    url = str(sys.argv[1])  # arg: URL string
except (IndexError, ValueError):
    print('Please enter URL')
    sys.exit(2)

response = urlopen(url)
print(response.readline())