Advertisement
Guest User

Untitled

a guest
Nov 29th, 2017
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.58 KB | None | 0 0
  1. from configparser import ConfigParser
  2. import requests
  3. from urllib.parse import urlparse, parse_qs
  4. import time
  5. import random
  6. import logging
  7. import sys
  8. from http.client import HTTPConnection
  9. from bs4 import BeautifulSoup
  10.  
  11. # HTTPConnection.debuglevel = 1
  12. # logging.basicConfig()
  13. # logging.getLogger().setLevel(logging.DEBUG)
  14. # requests_log = logging.getLogger("requests.packages.urllib3")
  15. # requests_log.setLevel(logging.DEBUG)
  16. # requests_log.propagate = True
  17.  
  18. country = 'HK'
  19. locale = 'en_HK'
  20. store = 'R499'
  21. part_number = 'MQA62ZP/A'
  22.  
  23. url = {}
  24. url_params = {}
  25.  
  26. proxies = {
  27. 'http': 'http://191.96.109.240:3199',
  28. 'https': 'https://191.96.109.240:3199'
  29. }
  30.  
  31. # cfg = ConfigParser()
  32. # cfg.read('config.ini')
  33. # MYSQL_HOST = cfg.get('mysql-server', 'host')
  34. # MYSQL_PORT = cfg.getint('mysql-server', 'port')
  35. # MYSQL_USER = cfg.get('mysql-server', 'user')
  36. # MYSQL_PASSWORD = cfg.get('mysql-server', 'password')
  37. # MYSQL_DATABASE = cfg.get('mysql-server', 'database')
  38. # db = pymysql.connect(host=MYSQL_HOST, port=MYSQL_PORT, user=MYSQL_USER, password=MYSQL_PASSWORD, db=MYSQL_DATABASE, charset='utf8mb4')
  39.  
  40. fn = 'debug.txt'
  41.  
  42. def test():
  43. s = requests.Session()
  44. # s.verify = "charles.cer"
  45. # s.verify = False
  46.  
  47. # response = s.request(
  48. # 'get',
  49. # 'https://ifconfig.co/ip',
  50. # proxies=proxies
  51. # )
  52. # print(response.text)
  53. # sys.exit()
  54.  
  55. response = s.request(
  56. 'get',
  57. 'https://reserve-prime.apple.com/' + country + '/' + locale + '/reserve/iPhoneX',
  58. headers={
  59. 'Connection': 'keep-alive',
  60. 'Pragma': 'no-cache',
  61. 'Cache-Control': 'no-cache',
  62. 'Upgrade-Insecure-Requests': '1',
  63. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  64. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  65. 'Accept-Encoding': 'gzip, deflate, br',
  66. 'Accept-Language': 'en-US,en;q=0.8'
  67. },
  68. params={
  69. 'quantity': '2',
  70. 'store': store,
  71. 'partNumber': part_number,
  72. 'channel': '1',
  73. 'sourceID': '',
  74. 'iUID': '',
  75. 'iuToken': '',
  76. 'iUP': 'N',
  77. 'appleCare': '',
  78. 'rv': '',
  79. 'path': '',
  80. 'plan': 'unlocked'
  81. },
  82. proxies=proxies
  83. )
  84.  
  85. if response.status_code != 200:
  86. print('step 1 failed invalid response code')
  87.  
  88. if response.status_code == 403 and response.url == 'https://www.apple.com/' + country.lower() + '/iphone/':
  89. print('maybe stock-out')
  90. sys.exit()
  91.  
  92. sp = BeautifulSoup(response.text, 'html.parser')
  93.  
  94. if sp.select('title')[0].get_text() != 'Sign In - Apple':
  95. print('step 1 failed invalid page')
  96. sys.exit(0)
  97.  
  98. signin_scnt = sp.select('#scnt')[0]['value']
  99. url['signin_page'] = response.url
  100. # https://signin.apple.com/IDMSWebAuth/signin?path=%2FAU%2Fen_AU%2Freserve%2FiPhone%3Fexecution%3De1s1%26p_left%3DAAAAAARVJ865qtn4hK8W1pG7eczwcmI45QNmcebdbu4mNGGKhw%253D%253D%26_eventId%3Dnext&p_time=1506399761&rv=1&language=AU-EN&p_left=AAAAAARVJ865qtn4hK8W1pG7eczwcmI45QNmcebdbu4mNGGKhw%3D%3D&appIdKey=db0114b11bdc2a139e5adff448a1d7325febef288258f0dc131d6ee9afe63df3
  101.  
  102. fh = open(fn, 'a+')
  103. fh.writelines([
  104. str(response.status_code) + '\n',
  105. response.url + '\n',
  106. str(response.headers) + '\n',
  107. response.text + '\n',
  108. '\n'
  109. ])
  110. fh.close()
  111.  
  112. qs = parse_qs(urlparse(response.url).query)
  113. url_params['path'] = qs['path'][0]
  114. url_params['rv'] = qs['rv'][0]
  115. url_params['language'] = qs['language'][0]
  116. url_params['p_left'] = qs['p_left'][0]
  117. url_params['appIdKey'] = qs['appIdKey'][0]
  118.  
  119. time.sleep(1)
  120.  
  121. response = s.request(
  122. 'get',
  123. 'https://signin.apple.com/appleauth/auth/signin',
  124. headers={
  125. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  126. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  127. 'Accept-Language': 'en-US,en;q=0.8',
  128. 'Accept-Encoding': 'gzip, deflate, br',
  129. 'Referer': url['signin_page'],
  130. 'Connection': 'keep-alive',
  131. 'Upgrade-Insecure-Requests': '1'
  132. },
  133. params={
  134. 'widgetKey': '40692a3a849499c31657eac1ec8123aa',
  135. 'language': url_params['language']
  136. },
  137. proxies=proxies
  138. )
  139.  
  140. if response.status_code != 200:
  141. print('signin widget failed')
  142.  
  143.  
  144. fh = open(fn, 'a+')
  145. fh.writelines([
  146. str(response.status_code) + '\n',
  147. response.url + '\n',
  148. str(response.headers) + '\n',
  149. response.text + '\n',
  150. '\n'
  151. ])
  152. fh.close()
  153.  
  154. url['signin_widget'] = response.url
  155. generated_scnt = str(int(1e10 * random.random()))
  156.  
  157. response = s.request(
  158. 'post',
  159. 'https://signin.apple.com/appleauth/jslog',
  160. headers={
  161. 'Connection': 'keep-alive',
  162. 'Pragma': 'no-cache',
  163. 'Cache-Control': 'no-cache',
  164. 'Accept': 'application/json',
  165. 'Origin': 'https://signin.apple.com',
  166. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  167. 'scnt': generated_scnt,
  168. 'Content-type': 'application/json',
  169. 'Referer': url['signin_widget'],
  170. 'Accept-Encoding': 'gzip, deflate, br',
  171. 'Accept-Language': 'en-US,en;q=0.8'
  172. },
  173. json={
  174. "type": "INFO",
  175. "title": "AppleAuthDebug",
  176. "message": "APPLE ID : Launching AppleAuth application."
  177. },
  178. proxies=proxies
  179. )
  180.  
  181. fh = open(fn, 'a+')
  182. fh.writelines([
  183. str(response.status_code) + '\n',
  184. response.url + '\n',
  185. str(response.headers) + '\n',
  186. response.text + '\n',
  187. '\n'
  188. ])
  189. fh.close()
  190.  
  191. if response.status_code != 204:
  192. print('signin jslog failed')
  193.  
  194. time.sleep(5)
  195.  
  196. response = s.request(
  197. 'post',
  198. 'https://signin.apple.com/appleauth/auth/signin',
  199. headers={
  200. 'Connection': 'keep-alive',
  201. 'Pragma': 'no-cache',
  202. 'Cache-Control': 'no-cache',
  203. 'X-Apple-App-Id': '942',
  204. 'X-Apple-Widget-Key': '40692a3a849499c31657eac1ec8123aa',
  205. 'Origin': 'https://signin.apple.com',
  206. 'X-Apple-I-FD-Client-Info': '{"U":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36","L":"en-US","Z":"GMT+08:00","V":"1.1","F":".Ga44j1e3NlY5BSo9z4ofjb75PaK4Vpjt.gEngMQEjZrVglE4Ww.GEFF0Yz3ccbbJYMLgiPFU77qZoOSix5ezdstlYysrhsui6.Whtd9KKaKEhO3f9p_nH1u_eH3BhxUC550ialT0iakA2zGUMnGWFfwMHDCQyFA2wv4qnvtCsABIlNU.3Io3.Nzl998tp7ppfAaZ6m1CdC5MQjGejuTDRNziCvTDfWk7QTPH_KO_IvLG9mhORoVjnjk3nKxUC54bQIxtzE9XXTneNufuyPBDjaY2ftckuyPB884akHGOg4C10EQh9dJ8aDhk6Hb9LarUqUdHz16rgPtTma1kxNGYicpw.Tf5.EKYgRc0mX3ivmeUeJzWKvqCSFQ_v9NA1OKq7GY5BNve.BNlYCa1nkBMfs.1av"}',
  207. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  208. 'X-Apple-Locale': url_params['language'],
  209. 'Content-Type': 'application/json',
  210. 'Accept': 'application/json, text/javascript, */*; q=0.01',
  211. 'X-Requested-With': 'XMLHttpRequest',
  212. 'Referer': url['signin_widget'],
  213. 'Accept-Encoding': 'gzip, deflate, br',
  214. 'Accept-Language': 'en-US,en;q=0.8'
  215. },
  216. json={
  217. "accountName": "Mark0202@ireserve.fun",
  218. "password": "1qaz@WSX3edc$RFV5tgb^YHN7ujm*IK<",
  219. "rememberMe": False
  220. },
  221. proxies=proxies
  222. )
  223.  
  224. if response.status_code != 200:
  225. print('signin failed')
  226.  
  227. fh = open(fn, 'a+')
  228. fh.writelines([
  229. str(response.status_code) + '\n',
  230. response.url + '\n',
  231. str(response.headers) + '\n',
  232. response.text + '\n',
  233. '\n'
  234. ])
  235. fh.close()
  236.  
  237. time.sleep(1)
  238.  
  239. response = s.request(
  240. 'post',
  241. 'https://signin.apple.com/IDMSWebAuth/signin',
  242. headers={
  243. 'Connection': 'keep-alive',
  244. 'Pragma': 'no-cache',
  245. 'Cache-Control': 'no-cache',
  246. 'Origin': 'https://signin.apple.com',
  247. 'Upgrade-Insecure-Requests': '1',
  248. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  249. 'Content-Type': 'application/x-www-form-urlencoded',
  250. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  251. 'Referer': url['signin_page'],
  252. 'Accept-Encoding': 'gzip, deflate, br',
  253. 'Accept-Language': 'en-US,en;q=0.8'
  254. },
  255. data={
  256. 'rememberMe': 'false',
  257. 'appIdKey': url_params['appIdKey'],
  258. 'language': url_params['language'],
  259. 'path': url_params['path'],
  260. 'rv': url_params['rv'],
  261. 'scnt': signin_scnt
  262. },
  263. proxies=proxies
  264. )
  265.  
  266. fh = open(fn, 'a+')
  267. fh.writelines([
  268. str(response.status_code) + '\n',
  269. response.url + '\n',
  270. str(response.headers) + '\n',
  271. response.text + '\n',
  272. '\n'
  273. ])
  274. fh.close()
  275.  
  276. if response.status_code != 200:
  277. print('post signin failed')
  278. sys.exit(0)
  279.  
  280. sp = BeautifulSoup(response.text, 'html.parser')
  281.  
  282. if sp.select('title')[0].get_text() == 'Your Registration Code - Apple':
  283. url['current'] = response.url
  284. response = s.request(
  285. 'get',
  286. url['current'] + '&ajaxSource=true&_eventId=context',
  287. headers={
  288. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  289. 'Accept': '*/*',
  290. 'Accept-Language': 'en-US,en;q=0.8',
  291. 'Accept-Encoding': 'gzip, deflate, br',
  292. 'Referer': url['current'],
  293. 'Connection': 'keep-alive'
  294. },
  295. proxies=proxies
  296. )
  297.  
  298. if response.status_code != 200:
  299. print('request sms code error')
  300. sys.exit(0)
  301.  
  302. response_data = response.json()
  303. # {
  304. # "firstTime": true,
  305. # "path": "",
  306. # "storeNumber": "R386",
  307. # "phoneCountryCode": "61",
  308. # "rv": "0",
  309. # "hcID": "tgSEoSTSZR/10CBiUOva2A4zNxU=",
  310. # "hcd": "0x00000000",
  311. # "partNumber": "MQ6M2X/A",
  312. # "keyword": "IPY7TS1HY9",
  313. # "_flowExecutionKey": "e1s2",
  314. # "appleCare": false,
  315. # "p_ie": "5ce2eb92-88e8-4739-bf4b-a655dbf09aaa"
  316. # }
  317.  
  318. print(response_data)
  319. sys.exit()
  320.  
  321. s.request(
  322. 'post',
  323. url['current'],
  324. headers={
  325. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
  326. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  327. 'Accept-Language': 'en-US,en;q=0.8',
  328. 'Accept-Encoding': 'gzip, deflate, br',
  329. 'Content-Type': 'application/x-www-form-urlencoded',
  330. 'Referer': url['current'],
  331. 'Connection': 'keep-alive',
  332. 'Upgrade-Insecure-Requests': '1'
  333. },
  334. data={
  335. 'phoneCountryCode': response_data['phoneCountryCode'],
  336. 'phoneNumber': '55112345',
  337. 'registrationCode': 'agda2s',
  338. '_eventId': 'next',
  339. '_flowExecutionKey': response_data['_flowExecutionKey'],
  340. 'p_ie': response_data['p_ie'],
  341. 'dims': 'kWa44j1e3NlY5BSo9z4ofjb75PaK4Vpjt4U_A6icW1F7MpwoNN5uQ1szHVyVxFAk.rVQdgAYx92u2p.j.2UMnGWFfwMHDCQyGMtHXTIKSEU0H8uszHVyVxFAk.XTrLjn.hlzuTDRI_37H02lLnU8zXVb50alnjk3nKxUC54jYE5ura1XmpRnmccbguaDeyjaY2ftckuyPBDjaY1HGOg3ZLQ0IFmaH1J9XWIUfR0odm_dhrxbuJjkWxv5iMgdVgEKXudQNvr9ey.EKY.6ekL3vgRcWAiwAwebu_TxYMJ5tTma1kxL57GYPrsiMTKQnlLZnjLHi5hyA_r_LwwKdBvzKAQxi3NlYic.lY5BqNAE.lTjV.CeN',
  342. 'dims': 's8a44j1e3NlY5BSo9z4ofjb75PaK4Vpjt4U_98uszHVyVxFAk.lzXJJIneGffLMC7EZ3QHPBirTYKUowRslzRQqwSM2V9htx39gkaxf7_OLgiPFMJhHFW_jftckkCoqAkCoq4ly_0x0uVMV0jftckcKyAd65hz7fwdGEM6uJ6o6e0T.5EwHXXTSHCSPmtd0wVYPIG_qvoPfybYb5EvYTrYesR0KjEcWKa3rhO3f9p_nH1zDz.ICMpwoNLyBwQfTN9AAKnE9XXTneNufuyPBDjaY2ftckuyPB884akHGOg4C29N9cFd1QhUfR0odm_dhrxbuJjkWxv5iMgdVgEL3Nv_Nk0ugN.xL1kbSY_38SraUWWUWIvqCSFQ_v9NA10Kq1xGY5BNve.BNlYCa1nkBMfs.6sc',
  343. 'dims': 'kWa44j1e3NlY5BSo9z4ofjb75PaK4Vpjt4U_A6icW1F7MpwoNN5uQ1szHVyVxFAk.rVQdgAYx92u2p.j.2UMnGWFfwMHDCQyGMtHXTIKSEU0H8uszHVyVxFAk.XTrLjn.hlzuTDRI_37H02lLnU8zXVb50alnjk3nKxUC54jYE5ura1XmpRnmccbguaDeyjaY2ftckuyPBDjaY1HGOg3ZLQ0IFma1dHcFFajpi.uJtHoqvynx9MsFyxYMAqJkL6elSJhgSv_urk0ugN.xL1kbSY_38SraUWHz22vqCSFQ_v9NA2pNNW5CfUXtStKjE4PIDxO9sPrsiMTKQnlLZnjxJhjqsGY5DuV25BNnOVgw24uy.577',
  344. 'dims': 'cWa44j1e3NlY5BSo9z4ofjb75PaK4Vpjt4U_A6icW1F7MpwoNN5uQ1szHVyVxFAk.rVQdgAYx92u2p.j.2UMnGWFfwMHDCQyGMtHXTIKSEU0H8uszHVyVxFAk.XTrLjn.hlzuTDRI_37H02lLnU8zXVb50alnjk3nKxUC54jYE5ura1XmpRnmccbguaDeyjaY2ftckuyPBDjaY1HGOg3ZLQ0IFma1dF2SH4yhk6Hb9LarUqUdHz16rgPtTma1kxLAe_hYjRcQs.xLB.Tf0NIilmX3ivnEkWUeCvqCSFQ_v9NA2pNNW5CfUXtStKjE4PIDxO9sPrsiMTKQnlLZnjxJhjqsGY5DuV25BNnOVgw24uy.BDL',
  345. 'hc': '5668008',
  346. 'hc': '1159657',
  347. 'miscHc': 'a=5668008,b=10719,c=0.8899999999994179,d=102.67000000000007',
  348. 'miscHc': 'a=1159657,b=4789,c=0.5649999999950523,d=108.98000000000002'
  349. }
  350. )
  351.  
  352. # response = s.request(
  353. # 'post',
  354. # 'https://reserve-prime.apple.com/AU/en_AU/reserve/iPhone?execution=e1s2',
  355. # headers={
  356. # 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0'
  357. # # Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  358. # # Accept-Language en-US,en;q=0.5
  359. # # Accept-Encoding gzip, deflate, br
  360. # # Content-Type application/x-www-form-urlencoded
  361. # # Referer https://reserve-prime.apple.com/AU/en_AU/reserve/iPhone?execution=e1s2
  362. # # Connection keep-alive
  363. # # Upgrade-Insecure-Requests 1
  364. # },
  365. # data={
  366. # # timeslot 5s4tzcpsCoZSzLPtcjfg2Cx7k5Av6mTFSPeqDxPQtZUiVk0lBnm3xK_E9jPJmHX2aLHFxwzPr6s6TJvUGiC2qi0ICn4fTHjUllOxOMg=_#_UHWhe-8cVqK6wZH07s07RwUUtOs.
  367. # # date 1506434400000
  368. # # firstName R
  369. # # lastName Leung
  370. # # email y2kbugleung@gmail.com
  371. # # phoneCountryCode 61
  372. # # phoneNumber abcde
  373. # # _eventId next
  374. # # _flowExecutionKey e1s2
  375. # # p_ie c64388fd-98d9-4ff3-aadf-f7ef70c1ae60
  376. # # dims kWa44j1e3NlY5BSo9z4ofjb75PaK4Vpjt4U_A6icW1F7MpwoNN5uQ1szHVyVxFAk.rVQdgAYx92u2p.j.2UMnGWFfwMHDCQyGMtHXTIKSEU0H8uszHVyVxFAk.XTrLjn5hlzuTDRI_37H02lLnU8zXVb5Calnjk3nKxUC54jYE5ura1XmpRnmccbguaDeyjaY2ftckuyPBDjaY1HGOg3ZLQ0IFV2pAAq_HNhyhk6Hb9LarUqUdHz16rgPtTma1kxLAe_hYjUfU.6elV2pNv69_DJF_rTJfy6gzCAwHCSFQ_v9NA2pNNW5CfUXtStKjE4PIDxO9sPrsiMTKQnlLZnjxJhjqsGY5DuV25BNnOVgw24uy.6T_
  377. # }
  378. # )
  379.  
  380. test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement