Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. import requests, json #ипортим библиотеки для отправки запроса и парсинга ответа JSON
  2. from python_rucaptcha import ReCaptchaV2 # импортим работу с капчей
  3.  
  4. """ ruCaptcha settings """
  5. SITE_KEY = '6LfTwxsTAAAAAK9lS9yRZdEWsatDuXqMK9kGbIhd' #ключ сайта
  6. PAGE_URL = 'https://www.walmart.com/account/giftcards/balance' #ссылка где капча
  7. RUCAPTCHA_KEY = '______' # ключ ruCaptcha
  8.  
  9. def getHeader(captcha_key,token):
  10.    header = { #формируем хеадер
  11.        'Host': 'www.walmart.com',
  12.        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
  13.        'Accept': 'application/json',
  14.        'Accept-Language': 'en',
  15.        'Accept-Encoding': 'gzip, deflate, br',
  16.        'Referer': 'https://www.walmart.com/account/giftcards/balance',
  17.        'content-type': 'application/json',
  18.        'wml-captcha': captcha_key, #подставляем полученое значение
  19.        'x-csrf-jwt': token,#подставляем полученое значение
  20.        'origin': 'https://www.walmart.com',
  21.        'Content-Length': '117',
  22.        'DNT': '1',
  23.        'Connection': 'keep-alive',
  24.        'Pragma': 'no-cache',
  25.        'Cache-Control': 'no-cache'
  26.    }
  27.  
  28.    return header
  29.  
  30. def getCaptcha(): # тут все с офф. доков
  31.    answer = ReCaptchaV2.ReCaptchaV2(rucaptcha_key=RUCAPTCHA_KEY).captcha_handler(site_key=SITE_KEY, page_url=PAGE_URL)
  32.  
  33.    if answer['errorId'] == 0:
  34.        return answer['captchaSolve']
  35.    elif answer['errorId'] == 1:
  36.        print(answer['errorBody'])
  37.        quit()
  38.  
  39. def getBalance(card, pin):
  40.    payload = {"captcha": "", "fieldErrors": [], "focusErrorFlag": "false", "number": card, "pin": pin, "useAlertRole": "true"} #данные формы
  41.    session = requests.Session()
  42.    
  43.    a = session.get('https://www.walmart.com/account/giftcards/balance') # получаем хеадеры в ответ
  44.    r = session.post("https://www.walmart.com/account/electrode/account/api/customer/:CID/gift-card/balance",
  45. headers=getHeader(getCaptcha(), #формируем хеадер, добавляем ответ капчи
  46. a.headers['X-Csrf-Jwt'] #формируем хеадер, добавляем занчение с хеадера первого входа
  47. ), data=payload # данные формы
  48. )
  49.  
  50.    session.close()
  51.    
  52.    if r.status_code == 200: # если код 200 - значит все хорошо
  53.        data = json.loads(r.text)
  54.        print("{}:{}|{}|{}\n".format(card,pin,data['balance'],data['currency']))
  55.    else: # тут явно ошибка
  56.        print('Error: '+r.text)
  57.  
  58.  
  59. getBalance("1111 1111 1111 1111", "1111")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement