test_urllib.py 579 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Author : liuyuqi
  5. @Contact : liuyuqi.gov@msn.cn
  6. @Time : 2019/08/11 10:27:41
  7. @Version : 1.0
  8. @License : (C)Copyright 2019
  9. @Desc : 垃圾的 urllib.request
  10. 404 页面不存在,就错误!
  11. '''
  12. import urllib.request
  13. url_page = "http://blog.yoqi.me"
  14. data = {}
  15. try:
  16. req = urllib.request.Request(
  17. url=url_page, data=urllib.parse.urlencode(data).encode(encoding='UTF8'))
  18. with urllib.request.urlopen(req) as res:
  19. print("http res:", res)
  20. except Exception as err:
  21. print("error:", err)