判斷網絡是否鏈接正常:python
#coding:utf-8
import urllib2
import sys
try:
request = urllib2.Request('http://www.baidu.com')
opener = urllib2.build_opener()
f= opener.open(request)
except urllib2.URLError,e:
sys.exit('connect failed')
else:
sys.stdout.write('Connected ')
版權聲明:本文爲博主原創文章,未經博主容許不得轉載。網絡