Advertisement
tastypear

暴力搜索筛选

Apr 4th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.54 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from urllib import urlopen
  3. import md5
  4. import base64
  5. #__metaclass__ = type
  6.  
  7. class switch(object):
  8.     def __init__(self, value):
  9.         self.value = value
  10.         self.fall = False
  11.     def __iter__(self):
  12.         yield self.match
  13.         raise StopIteration
  14.     def match(self, *args):
  15.         if self.fall or not args:
  16.             return True
  17.         elif self.value in args:
  18.             self.fall = True
  19.             return True
  20.         else:
  21.             return False
  22.  
  23. def resultOfSearch(keyword,page):
  24.     result = ''
  25.     APP_API_KEY = "loooooooooooooooooooool"#你猜
  26.     APP_API_BASEURI = "http://api.xxx.com/"#你再猜
  27.     APP_API_VERSION = "v1"
  28.     result = urlopen(APP_API_BASEURI+APP_API_VERSION+"/wpi.php?apikey="+APP_API_KEY+"&method=get_Search&keyword="+(((keyword).decode("GB2312")).encode("UTF-8")).replace(" ","%20")+"&p="+ repr(page)).read()
  29.     return result
  30.  
  31. def get_keyword(keyword):
  32.     keyword = keyword.decode("GB2312")
  33.  
  34. def fmtStr2u(srcStr):
  35.     result = ''
  36.     i = 0
  37.     while i < len(srcStr):
  38.         if srcStr[i]=='\\' and srcStr[i+1]=='u':
  39.             result += unichr(int(srcStr[i+2:i+6],16))
  40.             i += 6
  41.         elif srcStr[i]=='\\' and srcStr[i+1]=='/':
  42.             result += "/"
  43.             i += 2
  44.         else:
  45.             result += srcStr[i]
  46.             i += 1
  47.     return result
  48.  
  49. def get_apkId(apiResult):
  50.     apkID = apiResult[apiResult.index("apkId")+8:apiResult.index("apkName")-3]
  51.     return apkID
  52. def get_apkName(apiResult):
  53.     apkName = apiResult[apiResult.index("apkName")+10:apiResult.index("apkTitle")-3]
  54.     return apkName
  55. def get_apkTitle(apiResult):
  56.     apkTitle = apiResult[apiResult.index("apkTitle")+11:apiResult.index("apkVersionCode")-3]
  57.     apkTitle = fmtStr2u(apkTitle)
  58.     return apkTitle
  59. def get_apkVersionName(apiResult):
  60.     apkVersionName = apiResult[apiResult.index("apkVersionName")+17:apiResult.index("apkSize")-3]
  61.     apkVersionName = fmtStr2u(apkVersionName)
  62.     return apkVersionName
  63. def get_catId(apiResult):
  64.     catid = int(apiResult[apiResult.index("catid")+8:apiResult.index("downnum")-3])
  65.     return catid
  66. def get_apkDownUrl(apkId):
  67.     md5str = repr(md5.md5((apkId+"@W2x5B1C0")).hexdigest())
  68.     b64str = base64.encodestring(apkId + ",0,0,0,," + md5str[9:17])
  69.     apkDownUrl = "PrivateId = " + b64str
  70.     return apkDownUrl
  71. def catid2chs(catid):
  72.     arg = catid
  73.     for case in switch(arg):
  74.         if case(5):
  75.             return "系统工具".decode("GB2312"),
  76.             break
  77.         if case(59):
  78.             return "桌面插件".decode("GB2312")
  79.             break
  80.         if case(6):
  81.             return "主题美化".decode("GB2312")
  82.             break
  83.         if case(7):
  84.             return "社交聊天".decode("GB2312")
  85.             break          
  86.         if case(55):
  87.             return "咨询阅读".decode("GB2312")
  88.             break          
  89.         if case(8):
  90.             return "通讯网络".decode("GB2312")
  91.             break          
  92.         if case(9):
  93.             return "影音娱乐".decode("GB2312")
  94.             break          
  95.         if case(10):
  96.             return "出行拍照".decode("GB2312")
  97.             break          
  98.         if case(56):
  99.             return "实用工具".decode("GB2312")
  100.             break          
  101.         if case(12):
  102.             return "文档商务".decode("GB2312")
  103.             break
  104.         if case(11):
  105.             return "学习财经".decode("GB2312")
  106.             break
  107.         if case(13):
  108.             return "休闲游戏".decode("GB2312")
  109.             break
  110.         if case(14):
  111.             return "益智游戏".decode("GB2312")
  112.             break
  113.         if case(15):
  114.             return "棋牌游戏".decode("GB2312")
  115.             break          
  116.         if case(16):
  117.             return "体育赛车".decode("GB2312")
  118.             break          
  119.         if case(18):
  120.             return "掌上网游".decode("GB2312")
  121.             break          
  122.         if case(60):
  123.             return "策略塔防".decode("GB2312")
  124.             break          
  125.         if case():
  126.             return "bug"
  127.  
  128. def printList(result):
  129.     tmpkey = keyword + ' '
  130.     tmpkey = (tmpkey.decode("GB2312")).lower()
  131.    
  132.     a={}
  133.     j = 0
  134.     numOfDict = 0
  135.    
  136.     while len(tmpkey)!=0:
  137.         a[j]=tmpkey[:tmpkey.index(" ")]
  138.         tmpkey=tmpkey[len(a[j])+1:]
  139.         j+=1
  140.         numOfDict += 1
  141.    
  142.     baknum = numOfDict
  143.     i = 0  
  144.     while i < result.count("apkId"):
  145.         apkId = get_apkId(result)
  146.         apkVersionName = get_apkVersionName(result)
  147.         apkName = get_apkName(result)
  148.         apkTitle = get_apkTitle(result)
  149.         catId = get_catId(result)
  150.         flag = True
  151.        
  152.         numOfDict=baknum
  153.         while numOfDict !=0:
  154.             if a[numOfDict-1] in (apkTitle).lower():
  155.                 numOfDict -= 1
  156.             else:
  157.                 flag = False
  158.                 break
  159.                
  160.         if flag==True:
  161.             print fmtStr2u(catid2chs(catId)) + u" : " + apkTitle + u" " +apkVersionName
  162.             if catId >=13 and catId <=18 or catId == 60:
  163.                 cat = "game"
  164.             else:
  165.                 cat = "apk"
  166.             print "http://www.coolapk.com/" + cat + "-" + apkId + "-" + apkName + "/"
  167.             print get_apkDownUrl(apkId)
  168.        
  169.         result = result[result.index("}")+1:]
  170.    
  171. keyword = raw_input("keyword : ")
  172. print "\n"
  173. page = 1
  174. result = ''
  175. while(result!=u"data://[]"):
  176.     result = resultOfSearch(keyword,page)
  177.     printList(result)
  178.     page += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement