1 Star 0 Fork 0

dzc/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
internet_connection_py3.py 779 Bytes
一键复制 编辑 原始数据 按行查看 历史
cclauss 提交于 2019-03-12 16:17 +08:00 . Use print() function in both Python 2 and Python 3
from __future__ import print_function
import urllib2
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print("Testing Internet Connection")
print()
try:
urllib2.urlopen("http://google.com", timeout=2)#Tests if connection is up and running
print("Internet is working fine!")
print()
question = raw_input("Do you want to open a website? (Y/N): ")
if question == 'Y':
print()
search = raw_input("Input website to open (http://website.com) : ")
else:
os._exit(0)
except urllib2.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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdredboy/Python-1.git
git@gitee.com:sdredboy/Python-1.git
sdredboy
Python-1
Python-1
master

搜索帮助