Всем привет! Мне нужно спарсить данные с сайта:"https://www.gazprombank.ru/personal/courses/ ".При переходе на сайт вы видите курсы валют.Так вот,я подумал,что хватит 1 get запроса через request,но нет.Я в итоге не получил таблицу с валютами. Данные на сайт приходят через POST запрос и потом уже обрабатывается у пользователя. Что мне сделать? Может посоветуйте какой-то гайд или библиотеку. Всем спасибо за внимание к данной теме. (Доступа к API токену нельзя получить :D)
from curl_cffi import requests import json headers = { 'accept': '*/*', 'accept-language': 'ru,en;q=0.9', 'priority': 'u=1, i', 'referer': 'https://www.gazprombank.ru/personal/courses/', 'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132", "YaBrowser";v="25.2", "Yowser";v="2.5"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 YaBrowser/25.2.0.0 Safari/537.36', } params = { 'ab_segment': 'segment08', 'cityId': '617', 'version': '3', 'lang': 'ru', } api_url = 'https://www.gazprombank.ru/rest/exchange/rate' try: response = requests.get(api_url, params=params, headers=headers, impersonate="chrome110") response.raise_for_status() all_exchange_data = response.json() internet_bank_section = None for section in all_exchange_data: if section.get("code") == "exchange_rates_internet_bank": internet_bank_section = section break if not internet_bank_section or not internet_bank_section.get("content"): print("Не удалось найти данные для интернет-банка.") exit() content_details = internet_bank_section["content"][0] currency_rates = content_details.get("items") last_updated_info = content_details.get("updated") if not currency_rates: print("Не удалось найти список курсов валют.") exit() print("Курс валют") print(f"{'Букв. код':<10} {'Валюта обмена':<20} {'Единиц':<7} {'Продать':<7} {'Купить':<7}") print("-" * 55) for rate_info in currency_rates: currency_code = rate_info.get('ticker', 'N/A') currency_name = rate_info.get('tickerTitle', 'N/A') units = rate_info.get('unit', 'N/A') sell_rate = rate_info.get('buy', 'N/A') # Клиент продает банку buy_rate = rate_info.get('sell', 'N/A') # Клиент покупает у банка print(f"{currency_code:<10} {currency_name:<20} {str(units):<7} {str(sell_rate):<7} {str(buy_rate):<7}") if last_updated_info: print(f"\n{last_updated_info}") else: print("\nИнформация о времени обновления отсутствует.") except requests.exceptions.RequestException as e: print(f"Ошибка при запросе к серверу: {e}") except json.JSONDecodeError as e: print(f"Ошибка чтения данных от сервера: {e}") print("Полученный ответ:", response.text) except (KeyError, IndexError, TypeError) as e: print(f"Ошибка обработки полученных данных: {e}") except Exception as e: print(f"Произошла непредвиденная ошибка: {e}") Python from curl_cffi import requests import json headers = { 'accept': '*/*', 'accept-language': 'ru,en;q=0.9', 'priority': 'u=1, i', 'referer': 'https://www.gazprombank.ru/personal/courses/', 'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132", "YaBrowser";v="25.2", "Yowser";v="2.5"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 YaBrowser/25.2.0.0 Safari/537.36', } params = { 'ab_segment': 'segment08', 'cityId': '617', 'version': '3', 'lang': 'ru', } api_url = 'https://www.gazprombank.ru/rest/exchange/rate' try: response = requests.get(api_url, params=params, headers=headers, impersonate="chrome110") response.raise_for_status() all_exchange_data = response.json() internet_bank_section = None for section in all_exchange_data: if section.get("code") == "exchange_rates_internet_bank": internet_bank_section = section break if not internet_bank_section or not internet_bank_section.get("content"): print("Не удалось найти данные для интернет-банка.") exit() content_details = internet_bank_section["content"][0] currency_rates = content_details.get("items") last_updated_info = content_details.get("updated") if not currency_rates: print("Не удалось найти список курсов валют.") exit() print("Курс валют") print(f"{'Букв. код':<10} {'Валюта обмена':<20} {'Единиц':<7} {'Продать':<7} {'Купить':<7}") print("-" * 55) for rate_info in currency_rates: currency_code = rate_info.get('ticker', 'N/A') currency_name = rate_info.get('tickerTitle', 'N/A') units = rate_info.get('unit', 'N/A') sell_rate = rate_info.get('buy', 'N/A') # Клиент продает банку buy_rate = rate_info.get('sell', 'N/A') # Клиент покупает у банка print(f"{currency_code:<10} {currency_name:<20} {str(units):<7} {str(sell_rate):<7} {str(buy_rate):<7}") if last_updated_info: print(f"\n{last_updated_info}") else: print("\nИнформация о времени обновления отсутствует.") except requests.exceptions.RequestException as e: print(f"Ошибка при запросе к серверу: {e}") except json.JSONDecodeError as e: print(f"Ошибка чтения данных от сервера: {e}") print("Полученный ответ:", response.text) except (KeyError, IndexError, TypeError) as e: print(f"Ошибка обработки полученных данных: {e}") except Exception as e: print(f"Произошла непредвиденная ошибка: {e}")
Ознакомься с этим запросом 617-код москвы https://www.gazprombank.ru/rest/exchange/rate?ab_segment=segment12&cityId=617&version=3&lang=ru
wispik, в самом запросе смотри на F12 во вкладке Network, находишь запрос который порлуает курс валют и просто его копипастишь на requests. Там у запроса написаны и заголовки и параметры, иногда нужны куки, но в данном случае неи