Answer the question
In order to leave comments, you need to log in
How to parse the amount of Yandex money balance in Python?
How to parse the amount of Yandex money balance in Python.
Answer the question
In order to leave comments, you need to log in
1) Install yandex-money-sdk-python
2) Check balance
account_info = api.account_info()
print(account_info['balance'] )
before starting: pip install --user requests
in the cmd command line (it's also a terminal, it's also a console)
At the moment it works, my balance is parsing, it displays, there are no errors.
import requests, urllib.parse, json, re
s = requests.session()
ua = r"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"
s.headers = {"User-Agent": ua}
url = 'https://money.yandex.ru/'
login = 'vasya-ivanov'
password = 'secret'
resp = s.get(url, allow_redirects = True).content.decode("utf8")
if not "balance-widget__amount" in resp:
authurl = "https://passport.yandex.ru/auth?origin=money&retpath=https%3A%2F%2Fmoney.yandex.ru%2F"
resp = s.get(authurl, allow_redirects = True).content.decode("utf8")
token = re.search(r'data-csrf="([^"]+)"', resp).group(1)
resp = s.post(authurl, headers = {
"Referer":authurl
}, data = {
"retpath":url,
"fretpath":"",
"clean":"",
"service":"",
"origin":"",
"policy":"",
"is_pdd":"",
"csrf_token": token,
"login":login,
"hidden-password":password,
"passwd":password,
"twoweeks":"no"
}, allow_redirects = True).content.decode("utf8")
resp = s.get(url, allow_redirects = True).content.decode("utf8")
r = re.search(r'<div class="balance-widget__amount">.*?>([\d]+)<.*?>([\d]+)<', resp)
balance = float(r.group(1)+"."+r.group(2))
price_label = re.search(r'<span.*?price__label.*?">([^<]+)</span>', resp).group(1)
print("Я спарсил баланс!", balance, price_label)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question