
1 chinesejar 2017-09-16 11:10:04 +08:00 看似没有错误 |
2 qsnow6 2017-09-16 11:17:57 +08:00 没缩进 |
4 GlobalNPC 2017-09-16 11:26:15 +08:00 ``` #!/usr/bin/python ``` 哪里用 python3 了? |
5 everfight 2017-09-16 11:34:41 +08:00 试了下应该是 error 的类型错了 #!/usr/bin/python import urllib.request import urllib.error try: respOnse= urllib.request.urlopen('https://www.baidu.com',timeout=2) html = response.read().decode('utf-8') print(html) except: print('error') 打印的结果如下: <html> <head> <script> location.replace(location.href.replace("https://","http://")); </script> </head> <body> <noscript><meta http-equiv="refresh" cOntent="0;url=http://www.baidu.com/"></noscript> </body> </html> |
7 sunwei0325 2017-09-16 15:20:30 +08:00 #!/usr/bin/env python3 |
8 Valyrian 2017-09-16 15:28:43 +08:00 支持楼上,用 env |
9 ChristopherWu 2017-09-16 18:21:54 +08:00 f |
10 ChristopherWu 2017-09-16 18:22:24 +08:00 ``` import urllib.request import urllib.error try: respOnse= urllib.request.urlopen('https://www.baidu.com',timeout=2) html = response.read().decode('utf-8') print(html) except urllib.error.HTTPError as e: print('error') ``` 是没问题的。 输出的 html 也正常 |