去年 10 月份为了选车牌,研究发现的,现在贴出来,祝大家选到自己心仪的车牌:)
1# coding=utf-8 2import os 3import sys 4import urllib2 5import random 6import time 7 8_t = '%d' %time.time() 9_r = '%d' %(random.random()*1000) 10_fname = 'num_list_%s.txt' 11 12_c1 = {'_t': '%s', '_list': ('L')}; 13_c2 = {'_t': '%d', '_list': range(1, 2)}; 14_c3 = {'_t': '%s', '_list': ('X')}; 15_c4 = {'_t': '%d', '_list': range(0, 10)}; 16_c5 = {'_t': '%d', '_list': range(0, 10)}; 17 18url = 'http://117.36.53.122:9085/zzxh/business/BusinessAction.do?' 19url += 'actiontype=xhgzvalidate&timeStamp='+_t+_r+'&hpzl=02&hphm1=A' 20url += '&hphm2='+_c1['_t']+'&hphm3='+_c2['_t']+'&hphm4='+_c3['_t']+'&hphm5='+_c4['_t']+'&hphm6='+_c5['_t'] 21num = _c1['_t']+_c2['_t']+_c3['_t']+_c4['_t']+_c5['_t'] 22 23### get remote content 24def file_clear(fname): 25 _f = open(fname, 'w+') 26 _f.write('Generated by mrasong at '+time.strftime('%Y-%m-%d %H:%M:%S')+'\n') 27 _f.close() 28 return 29 30def file_get_contents(url): 31 try: 32 _f = urllib2.urlopen(url, timeout=5) 33 _content = _f.read() 34 _content = _content.decode('gbk').encode('utf-8') 35 return _content.strip()+'\n' 36 except Exception, e: 37 return e 38 39def file_put_contents(fname, data): 40 _f = open(fname, 'a'); 41 _f.write(str(data)) 42 _f.close() 43 return 44 45for _n1 in _c1['_list']: 46 _file_name = _fname % _n1 47 file_clear(_file_name) 48 for _n2 in _c2['_list']: 49 for _n3 in _c3['_list']: 50 for _n4 in _c4['_list']: 51 for _n5 in _c5['_list']: 52 #url 53 _u = (url % ( _n1, _n2, _n3, _n4, _n5, )) 54 #car num 55 _num = (num % ( _n1, _n2, _n3, _n4, _n5, )) 56 _content = file_get_contents(_u) 57 58 if( _content[0:2]!='00' ): 59 continue 60 61 _content = _num+'\t'+_content[2:] 62 file_put_contents(_file_name, _content) 63 print(_num) 64 #end _c5 65 #end _c4 66 #end _c3 67 #end _c2 68 #os.system('pause') 69 70#end _c1 附:
...