python Python模块:urllib:readline URL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python模块: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())

以上是关于python Python模块:urllib:readline URL的主要内容,如果未能解决你的问题,请参考以下文章

python3.5中没有urllib2怎么处理?

python2.7导入mysqldb

python—爬虫

python—爬虫

python爬虫思路

python爬虫思路