Created
February 8, 2015 02:44
-
-
Save taojy123/f9e490e24796dfc4aac6 to your computer and use it in GitHub Desktop.
通过互联网获取当前时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import re | |
import time | |
def get_online_seconds(): | |
p = urllib2.urlopen("http://www.baidu.com/").read() | |
r = re.findall(r'serverTime : "(.*?)"', p) | |
if r: | |
t = r[0] | |
else: | |
t = 0 | |
return int(t) | |
t = get_online_seconds() | |
print t | |
print time.ctime(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment