L
L
Lelouch Lamperouche2020-08-26 22:51:02
YouTube
Lelouch Lamperouche, 2020-08-26 22:51:02

How to login to YouTube using Python (Request)?

Good evening.
I set myself the task of parsing this from Youtube Library Music ( https://www.youtube.com/audiolibrary/music ) using the query method.

Naturally youtube requested authorization.

I haven't worked much with the requests module, and I can't figure out exactly which way to solve this problem would be more correct:

Try sending an Authorization request first: ( https://accounts.google.com/signin/v2/identifier?f.. . ) , and then continue to perform the parsing task in the saved session ..

Or go directly to the link ( https://www.youtube.com/audiolibrary/music ) and log in there.

This question is quite simple, and the problem is not in it.
The problem is that I don't know how to login. With a post request, the Form Data (there must be a login and password sent in it) contains a lot of oddities, but I still don’t understand where and where to insert the password.

It’s clear that YouTube authorization is not a dating forum, but it can’t be all that problematic, can it?

What is my mistake and where should I look to solve it?
Having searched on Habré, I found information that you can’t rummage around with simple post-get requests on YouTube, is it really impossible to do without selenium? And if with him, then how to transfer the session opened with the help of it in order to work with it further through requests?

I will be glad to any opinion.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2020-08-26
@Lelush

The algorithm is simple.
Determine if it is possible to get data by disabling JS. For example, using this instruction
https://developers.google.com/web/tools/chrome-dev...
If the necessary data does not appear with disabled JS, then you have two options:
- Understand the logic of obtaining data, picking JS scripts that process data. You can find them on the Sources tab

Sources tab

5f46c1453c6f9427816125.png

- Use Selenium, imitating user actions
To select elements on the page, you will need the XPath query language Tutor Xpath Helper
debugging extension
img
5f46c263ee5d2373188117.png

D
Daria Motorina, 2020-08-26
@glaphire

Login and parsing through selenium will be more reliable, YouTube will not just allow itself to be parsed (except through the official api, if it exists for this service)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question