店播爬取Python脚本

xlog03.py 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import hashlib
  2. from urllib import request, parse
  3. import time
  4. import gzip
  5. byteTable1 = "D6 28 3B 71 70 76 BE 1B A4 FE 19 57 5E 6C BC 21 B2 14 37 7D 8C A2 FA 67 55 6A 95 E3 FA 67 78 ED 8E 55 33 89 A8 CE 36 B3 5C D6 B2 6F 96 C4 34 B9 6A EC 34 95 C4 FA 72 FF B8 42 8D FB EC 70 F0 85 46 D8 B2 A1 E0 CE AE 4B 7D AE A4 87 CE E3 AC 51 55 C4 36 AD FC C4 EA 97 70 6A 85 37 6A C8 68 FA FE B0 33 B9 67 7E CE E3 CC 86 D6 9F 76 74 89 E9 DA 9C 78 C5 95 AA B0 34 B3 F2 7D B2 A2 ED E0 B5 B6 88 95 D1 51 D6 9E 7D D1 C8 F9 B7 70 CC 9C B6 92 C5 FA DD 9F 28 DA C7 E0 CA 95 B2 DA 34 97 CE 74 FA 37 E9 7D C4 A2 37 FB FA F1 CF AA 89 7D 55 AE 87 BC F5 E9 6A C4 68 C7 FA 76 85 14 D0 D0 E5 CE FF 19 D6 E5 D6 CC F1 F4 6C E9 E7 89 B2 B7 AE 28 89 BE 5E DC 87 6C F7 51 F2 67 78 AE B3 4B A2 B3 21 3B 55 F8 B3 76 B2 CF B3 B3 FF B3 5E 71 7D FA FC FF A8 7D FE D8 9C 1B C4 6A F9 88 B5 E5"
  6. def getXGon(url, stub, cookies):
  7. NULL_MD5_STRING = "00000000000000000000000000000000"
  8. sb = ""
  9. if len(url) < 1:
  10. sb = NULL_MD5_STRING
  11. else:
  12. sb = encryption(url)
  13. if len(stub) < 1:
  14. sb += NULL_MD5_STRING
  15. else:
  16. sb += stub
  17. if len(cookies) < 1:
  18. sb += NULL_MD5_STRING
  19. else:
  20. sb += encryption(cookies)
  21. if 'sessionid' in cookies:
  22. index = cookies.index("sessionid=")
  23. sessionid = cookies[index + 10:]
  24. if sessionid.__contains__(';'):
  25. endIndex = sessionid.index(';')
  26. sessionid = sessionid[:endIndex]
  27. sb += encryption(sessionid)
  28. else:
  29. sb += NULL_MD5_STRING
  30. return sb
  31. def encryption(url):
  32. obj = hashlib.md5() # 先创建一个md5的对象
  33. # 写入要加密的字节
  34. obj.update(url.encode("UTF-8"))
  35. # 获取密文
  36. secret = obj.hexdigest()
  37. return secret.lower()
  38. def initialize(data):
  39. myhex = 0
  40. byteTable2 = byteTable1.split(" ")
  41. for i in range(len(data)):
  42. hex1 = 0
  43. if i == 0:
  44. hex1 = int(byteTable2[int(byteTable2[0], 16) - 1], 16)
  45. byteTable2[i] = hex(hex1)
  46. # byteTable2[i] = Integer.toHexString(hex1);
  47. elif i == 1:
  48. temp = int("D6", 16) + int("28", 16)
  49. if temp > 256:
  50. temp -= 256
  51. hex1 = int(byteTable2[temp - 1], 16)
  52. myhex = temp
  53. byteTable2[i] = hex(hex1)
  54. else:
  55. temp = myhex + int(byteTable2[i], 16)
  56. if temp > 256:
  57. temp -= 256
  58. hex1 = int(byteTable2[temp - 1], 16)
  59. myhex = temp
  60. byteTable2[i] = hex(hex1)
  61. if hex1 * 2 > 256:
  62. hex1 = hex1 * 2 - 256
  63. else:
  64. hex1 = hex1 * 2
  65. hex2 = byteTable2[hex1 - 1]
  66. result = int(hex2, 16) ^ int(data[i], 16)
  67. data[i] = hex(result)
  68. for i in range(len(data)):
  69. data[i] = data[i].replace("0x", "")
  70. return data
  71. def handle(data):
  72. for i in range(len(data)):
  73. byte1 = data[i]
  74. if len(byte1) < 2:
  75. byte1 += '0'
  76. else:
  77. byte1 = data[i][1] + data[i][0]
  78. if i < len(data) - 1:
  79. byte1 = hex(int(byte1, 16) ^ int(data[i + 1], 16)).replace("0x", "")
  80. else:
  81. byte1 = hex(int(byte1, 16) ^ int(data[0], 16)).replace("0x", "")
  82. byte1 = byte1.replace("0x", "")
  83. a = (int(byte1, 16) & int("AA", 16)) / 2
  84. a = int(abs(a))
  85. byte2 = ((int(byte1, 16) & int("55", 16)) * 2) | a
  86. byte2 = ((byte2 & int("33", 16)) * 4) | (int)((byte2 & int("cc", 16)) / 4)
  87. byte3 = hex(byte2).replace("0x", "")
  88. if len(byte3) > 1:
  89. byte3 = byte3[1] + byte3[0]
  90. else:
  91. byte3 += "0"
  92. byte4 = int(byte3, 16) ^ int("FF", 16)
  93. byte4 = byte4 ^ int("14", 16)
  94. data[i] = hex(byte4).replace("0x", "")
  95. return data
  96. def xGorgon(timeMillis, inputBytes):
  97. data1 = []
  98. data1.append("3")
  99. data1.append("61")
  100. data1.append("41")
  101. data1.append("10")
  102. data1.append("80")
  103. data1.append("0")
  104. data2 = input(timeMillis, inputBytes)
  105. data2 = initialize(data2)
  106. data2 = handle(data2)
  107. for i in range(len(data2)):
  108. data1.append(data2[i])
  109. xGorgonStr = ""
  110. for i in range(len(data1)):
  111. temp = data1[i] + ""
  112. if len(temp) > 1:
  113. xGorgonStr += temp
  114. else:
  115. xGorgonStr += "0"
  116. xGorgonStr += temp
  117. return xGorgonStr
  118. def input(timeMillis, inputBytes):
  119. result = []
  120. for i in range(4):
  121. if inputBytes[i] < 0:
  122. temp = hex(inputBytes[i]) + ''
  123. temp = temp[6:]
  124. result.append(temp)
  125. else:
  126. temp = hex(inputBytes[i]) + ''
  127. result.append(temp)
  128. for i in range(4):
  129. result.append("0")
  130. for i in range(4):
  131. if inputBytes[i + 32] < 0:
  132. result.append(hex(inputBytes[i + 32]) + '')[6:]
  133. else:
  134. result.append(hex(inputBytes[i + 32]) + '')
  135. for i in range(4):
  136. result.append("0")
  137. tempByte = hex(int(timeMillis)) + ""
  138. tempByte = tempByte.replace("0x", "")
  139. for i in range(4):
  140. a = tempByte[i * 2:2 * i + 2]
  141. result.append(tempByte[i * 2:2 * i + 2])
  142. for i in range(len(result)):
  143. result[i] = result[i].replace("0x", "")
  144. return result
  145. def strToByte(str):
  146. length = len(str)
  147. str2 = str
  148. bArr = []
  149. i = 0
  150. while i < length:
  151. # bArr[i/2] = b'\xff\xff\xff'+(str2hex(str2[i]) << 4+str2hex(str2[i+1])).to_bytes(1, "big")
  152. a = str2[i]
  153. b = str2[1 + i]
  154. c = ((str2hex(a) << 4) + str2hex(b))
  155. bArr.append(c)
  156. i += 2
  157. return bArr
  158. def str2hex(s):
  159. odata = 0
  160. su = s.upper()
  161. for c in su:
  162. tmp = ord(c)
  163. if tmp <= ord('9'):
  164. odata = odata << 4
  165. odata += tmp - ord('0')
  166. elif ord('A') <= tmp <= ord('F'):
  167. odata = odata << 4
  168. odata += tmp - ord('A') + 10
  169. return odata
  170. def doGetGzip(url, headers, charset):
  171. req = request.Request(url)
  172. for key in headers:
  173. req.add_header(key, headers[key])
  174. with request.urlopen(req) as f:
  175. data = f.read()
  176. return gzip.decompress(data).decode()
  177. def doPostGzip(url, headers, charset, params):
  178. data = parse.urlencode(params).encode(encoding='UTF8')
  179. req = request.Request(url)
  180. for key in headers:
  181. req.add_header(key, headers[key])
  182. with request.urlopen(req, data=data) as f:
  183. data = f.read()
  184. return gzip.decompress(data).decode()
  185. if __name__ == "__main__":
  186. pass