B
B
Bruh_h_h_h2022-02-12 17:59:39
Python
Bruh_h_h_h, 2022-02-12 17:59:39

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)

This is what the json file outputs, where I am outputting
"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

3 answer(s)
D
Dimonchik, 2022-02-12
@dimonchik2013

first
https://www.commentedout.dev/2020-08-02-copy-reque...
then
https://networkdirection.net/python/resources/gene...

S
Sergey Karbivnichy, 2022-02-12
@hottabxp

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)

The output is json:
JSON
{"items":[{"id":1627816766,"title":"Biliardino per bambini ","price":"20.0","discount":null,"currency":"EUR","brand_title":"Bambini","size_title":"","is_for_swap":false,"user":{"id":69909841,"login":"capitanleox","profile_url":"https://www.vinted.it/member/69909841-capitanleox"...
Бла бла бла...

PS: You can fasten requests.Session ()

A
Alexander Nesterov, 2022-02-12
@AlexNest

Well, obviously the site requires a specific token for authorization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question