1 Star 0 Fork 0

fanyangchu/PythonCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
internet_connection_py3.py 764 Bytes
一键复制 编辑 原始数据 按行查看 历史
Jérôme Krell 提交于 2019-10-10 14:22 . Reformat Code by PyCharm-Community
from __future__ import print_function
import os
import urllib.request
from selenium import webdriver
print("Testing Internet Connection")
print()
try:
urllib.request.urlopen("http://google.com", timeout=2) # Tests if connection is up and running
print("Internet is working fine!")
print()
question = input("Do you want to open a website? (Y/N): ")
if question == 'Y':
print()
search = input("Input website to open (http://website.com) : ")
else:
os._exit(0)
except urllib.error.URLError:
print("No internet connection!") # Output if no connection
browser = webdriver.Firefox()
browser.get(search)
os.system('cls') # os.system('clear') if Linux
print("[+] Website " + search + " opened!")
browser.close()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fanych/pythoncode.git
git@gitee.com:fanych/pythoncode.git
fanych
pythoncode
PythonCode
master

搜索帮助