去年10月份为了选车牌,研究发现的,现在贴出来,祝大家选到自己心仪的车牌:)
# coding=utf-8
import os
import sys
import urllib2
import random
import time
_t = '%d' %time.time()
_r = '%d' %(random.random()*1000)
_fname = 'num_list_%s.txt'
_c1 = {'_t': '%s', '_list': ('L')};
_c2 = {'_t': '%d', '_list': range(1, 2)};
_c3 = {'_t': '%s', '_list': ('X')};
_c4 = {'_t': '%d', '_list': range(0, 10)};
_c5 = {'_t': '%d', '_list': range(0, 10)};
url = 'http://117.36.53.122:9085/zzxh/business/BusinessAction.do?'
url += 'actiontype=xhgzvalidate&timeStamp='+_t+_r+'&hpzl=02&hphm1=A'
url += '&hphm2='+_c1['_t']+'&hphm3='+_c2['_t']+'&hphm4='+_c3['_t']+'&hphm5='+_c4['_t']+'&hphm6='+_c5['_t']
num = _c1['_t']+_c2['_t']+_c3['_t']+_c4['_t']+_c5['_t']
### get remote content
def file_clear(fname):
_f = open(fname, 'w+')
_f.write('Generated by mrasong at '+time.strftime('%Y-%m-%d %H:%M:%S')+'\n')
_f.close()
return
def file_get_contents(url):
try:
_f = urllib2.urlopen(url, timeout=5)
_content = _f.read()
_content = _content.decode('gbk').encode('utf-8')
return _content.strip()+'\n'
except Exception, e:
return e
def file_put_contents(fname, data):
_f = open(fname, 'a');
_f.write(str(data))
_f.close()
return
for _n1 in _c1['_list']:
_file_name = _fname % _n1
file_clear(_file_name)
for _n2 in _c2['_list']:
for _n3 in _c3['_list']:
for _n4 in _c4['_list']:
for _n5 in _c5['_list']:
#url
_u = (url % ( _n1, _n2, _n3, _n4, _n5, ))
#car num
_num = (num % ( _n1, _n2, _n3, _n4, _n5, ))
_content = file_get_contents(_u)
if( _content[0:2]!='00' ):
continue
_content = _num+'\t'+_content[2:]
file_put_contents(_file_name, _content)
print(_num)
#end _c5
#end _c4
#end _c3
#end _c2
#os.system('pause')
#end _c1
附: