hello.py 695 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. ' a test module '
  4. __author__ = 'Michael Liao'
  5. import sys
  6. from bs4 import BeautifulSoup # 网页解析html文档
  7. import re # 正则表达式
  8. import urllib.request
  9. import urllib.error # 指定url获取网页数据
  10. import sqlite3 # 数据存储
  11. def test():
  12. args = sys.argv
  13. if len(args) == 1:
  14. print('Hello, world!')
  15. elif len(args) == 2:
  16. print('Hello, %s!' % args[1])
  17. else:
  18. print('Too many arguments!')
  19. path = "http://wwww.baidu.com"
  20. askUrl(path)
  21. def askUrl(path):
  22. response = urllib.request.urlopen(path)
  23. print(response.read().decode("utf-8"))
  24. if __name__ == '__main__':
  25. test()