|
- import time
- import urllib2
- import json
- def getJsonData(arg):
- url = "http://ssc.028pay.cn/go.php"
- cmd = "?cmd=" + arg
- request = urllib2.Request(url + cmd)
- response = urllib2.urlopen(request)
- data = response.read()
- return data
- def getTime(arg):
- now = time.localtime();
- tmp = time.strftime(arg,now)
- tmp = int(tmp)
- return tmp
- def getJsonItem(jsonData,arg):
- json_str = jsonData.decode("UTF-8")
- json_data = json.loads(json_str)
- return json_data[arg]
- while True:
- time.sleep(1)
- hour = getTime("%H")
- minute = getTime("%M") % 10
- second = getTime("%S") % 10
- if (hour >= 9 or hour <= 1):
- if (minute >= 0 and minute <= 5):
- if(second == 0):
- jsonData = getJsonData("check")
- status = getJsonItem(jsonData, "status")
- if(status == False):
- getJsonData("lecai")
- print("suess")
- else:
- print("along")
- else:
- print("no at second")
- else:
- print("no at minute")
复制代码 上面的上win 下的代码
win 下面的解释器是 2.6.6
- #! /usr/bin/python2.6
- import time
- import urllib2
- import json
- def getJsonData(arg):
- url = "http://ssc.028pay.cn/go.php"
- cmd = "?cmd=" + arg
- request = urllib2.Request(url + cmd)
- response = urllib2.urlopen(request)
- data = response.read()
- return data
- def getTime(arg):
- now = time.localtime();
- tmp = time.strftime(arg,now)
- tmp = int(tmp)
- return tmp
- def getJsonItem(jsonData,arg):
- json_str = jsonData.decode("UTF-8")
- json_data = json.loads(json_str)
- return json_data[arg]
- while True:
- time.sleep(1)
- hour = getTime("%H")
- minute = getTime("%M") % 10
- second = getTime("%S") % 10
- if (hour >= 9 or hour <= 1):
- if (minute >= 0 and minute <= 5):
- if(second == 0):
- jsonData = getJsonData("check")
- status = getJsonItem(jsonData, "status")
- if(status == False):
- getJsonData("lecai")
复制代码 这个linux的代码
linux下的解释器也是 2.6
这是错误提示,为毛呀
- Traceback (most recent call last):
- File "/www/wdlinux/python/task.py", line 34, in <module>
- jsonData = getJsonData("check")
- File "/www/wdlinux/python/task.py", line 11, in getJsonData
- response = urllib2.urlopen(request)
- File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
- return _opener.open(url, data, timeout)
- File "/usr/lib64/python2.6/urllib2.py", line 397, in open
- response = meth(req, response)
- File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
- 'http', request, response, code, msg, hdrs)
- File "/usr/lib64/python2.6/urllib2.py", line 435, in error
- return self._call_chain(*args)
- File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
- result = func(*args)
- File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
- raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
- urllib2.HTTPError: HTTP Error 403: Forbidden
复制代码
|
|