Answer the question
In order to leave comments, you need to log in
How to solve this problem in writing a parser?
For the first time I want to write something more than enumeration of numbers from 1 to 100)
I wanted to parse vinted to give a list of all products on the page, but even at the first stages there are problems, help me solve it)
from fake_useragent import UserAgent
import requests
import json
ua = UserAgent()
def collect_data():
response = requests.get(
url='https://www.vinted.it/api/v2/catalog/items?catalog_ids=1193&color_ids=&brand_ids=&size_ids=&material_ids=&status_ids=&is_for_swap=0&page=1&per_page=24&time=1644673298&search_session_id=&',
headers={'user-agent': f'{ua.random}'}
)
with open('result.json', 'w') as file:
json.dump(response.json(), file, indent=4, ensure_ascii=False)
def main():
collect_data()
if __name__ == '__main__':
main()
print(ua.random)
"code": 100,
"message": "Token d'authentification invalide",
"message_code": "invalid_authentication_token"
Answer the question
In order to leave comments, you need to log in
first
https://www.commentedout.dev/2020-08-02-copy-reque...
then
https://networkdirection.net/python/resources/gene...
1) You need to save cookies with the name _vinted_fr_session (either from the main page or from any other)
2) In each request you need to pass a cookie with the name _vinted_fr_session
import requests
response = requests.get('https://www.vinted.co.uk/') # Загружаем главную страницу для получения cookies
x = response.cookies.get('_vinted_fr_session') # Сохраняем в переменную x cookie с именем _vinted_fr_session
params = ( # Параметры
('catalog_ids', '1193'),
('color_ids', ''),
('brand_ids', ''),
('size_ids', ''),
('material_ids', ''),
('status_ids', ''),
('is_for_swap', '0'),
('page', '1'),
('per_page', '24'),
('time', '1644673298'),
)
response = requests.get('https://www.vinted.it/api/v2/catalog/items',params=params, cookies={'_vinted_fr_session':x}) # Передаем параметры и cookie с именем _vinted_fr_session
print(response.text)
Well, obviously the site requires a specific token for authorization.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question