Тёмный

Python Selenium Tutorial #7 - Save & Reuse Cookies 

Michael Kitas
Подписаться 8 тыс.
Просмотров 27 тыс.
50% 1

💥 Use Michael at checkout to Get Extra 2GB of proxy for any package (except trial): go.nodemaven.c...
🤖 CapSolver Captcha Solving Service: bit.ly/capsolv...
🤖 2captcha Captcha Solving Service: bit.ly/2captch...
📸 Capture Screenshot API: capturescreens...
This selenium tutorial is designed for beginners to learn how to use the Python selenium library to perform web scraping, testing, and creating website bots. Selenium is a Python library that provides a high-level API to control Chrome or Chromium and Firefox or Geckodriver over the DevTools Protocol. Selenium runs non-headless by default but can be configured to run headless.
Playlist: • Python Selenium Tutorial
Code: github.com/mic...
Join our Discord: / discord
Gecko Driver: github.com/moz...
Chrome Driver: chromedriver.c...
Download Visual Studio Code: code.visualstu...
Download Python: www.python.org...
Selenium Library: pypi.org/proje...
Donate
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
PayPal: support@websidev.com
Bitcoin Wallet: bc1q05j8gcnq4mzvgj603cxdc8xxck4jgnu2ljsrt4
Ethereum Wallet: 0x5e7BD4f473f153d400b39D593A55D68Ce80F8a2e
Social
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Website: websidev.com
Linkedin: / michael-kitas-638aa4209
Instagram: / michael_kitas
Github: github.com/mic...
Business Email: support@websidev.com
Tags:
Python Selenium Tutorial
Full Course Selenium
Python Selenium
Web Scraping Full Course
Python Selenium Web Scraping Full Course
#selenium #python #webscraping

Опубликовано:

 

21 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 80   
@adarmawan117
@adarmawan117 8 месяцев назад
Ah, the key is 1. Load the login page 2. Load cookies, and add to the driver 3. Re-load dashboard/page after login. 4. DONE THANKS BROOOO. YOU SAVE MY LIFE. ❤ YOU MUST KEEP UPDATE THE PLAYLIST. I LIKE IT!!!
@lukethomas5053
@lukethomas5053 Год назад
Awesome tutorial, this is the first method I've found that actually works!
@manoellevy7867
@manoellevy7867 11 месяцев назад
you sir are a god amongst ants. ty
@softwareengineer8923
@softwareengineer8923 Год назад
This video helped me a lot,thanks!
@javovsci
@javovsci 2 года назад
BRO, I FUCKING LOVE YOU, YOU SAVED ALL MY WORK AND HELPED ME A LOT. I LOVE YOU!!! THANKS FOR THAT VIDEO!!!
@quangduydang299
@quangduydang299 2 года назад
really awesome!!! here what I found many times
@computernetworking6061
@computernetworking6061 Год назад
You saved my day bro, Great work!
@adscft7597
@adscft7597 Год назад
great work Michael!
@jw200
@jw200 Год назад
Perfect. I need it for my bot
@praveenverma2881
@praveenverma2881 2 года назад
Awesome brother... Love your videos
@MaahiVFX
@MaahiVFX Год назад
Thankyou it worked for me
@javiergonzalez7207
@javiergonzalez7207 Год назад
I'm trying to start undetectable selenium with a real session, using --user-data-dir, it loads the web, with the profile but it doesn't redirect to the get url, it just opens the browser! do you know what can happen?
@MichaelKitas
@MichaelKitas Год назад
Does it show any errors?
@vijayragavan839
@vijayragavan839 Год назад
Very Innovative
@aminatawillane3437
@aminatawillane3437 2 года назад
Hello @Michael Kitas Thanks for the video.Well, I always running through that error while trying to log in my website : RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. Even though I' ve added the "if __name__ == '__main__':" line in my main file. Do you please have any idea about how to fix it?
@MichaelKitas
@MichaelKitas 2 года назад
Can you copy paste that part from my code and check again?
@bhavanakedari1009
@bhavanakedari1009 Год назад
hey i've been following your video, it's honestly great! but i'm facing an issue with svaing the cookies in the pkl file. it shows a 'cookies.pkl is not UTF-8 encoded, saving disabled' in the cookies.pkl file. i've changed the setting in chrome and also manually encoded the cookies into UTF-8 but it's still showing me the same error. can you please help me fix it?
@MichaelKitas
@MichaelKitas Год назад
Hey, it sounds like you're trying to open cookies.pkl in a text editor, but it's a binary file, not a text file. Don't try to change its encoding; it's meant to be used directly by your script. Use pickle.load() in your Python script to read the cookies. Ensure your script has the right permissions to write the file, and you're using the correct path. Also, check if any software like antivirus is interfering. Hope this helps
@shakils1921
@shakils1921 2 года назад
Is there anyway i can log in manually and save the cookies. then load through pickle? asking this because, After login using your previous code few times Google can not sign in anymore. just says ============== Couldn’t sign you in This browser or app may not be secure. Learn more.. ============== but it worked previously. Thank
@MichaelKitas
@MichaelKitas 2 года назад
Maybr create a script which saves cookies after a specific timeout, within that timeout login manually while of course you are using the script
@seanlee1577
@seanlee1577 8 месяцев назад
It works! Thanks bro!
@pastorjose9416
@pastorjose9416 2 года назад
You saved my day . Thank you...
@akshatmalhotra6442
@akshatmalhotra6442 2 года назад
Hello sir, I wanted to ask a question that how to store multiple cookies in aa text file and login them all using for i in range:
@MichaelKitas
@MichaelKitas 2 года назад
The same way I save them and use them, you use the same functionality
@vijayragavan839
@vijayragavan839 Год назад
@michael Kitas Sir How Can I extend the Expiry Date of the Cookie With the PKL file On Execution with For Loop
@MichaelKitas
@MichaelKitas Год назад
You can't extend the expiry date of a cookie that is already created
@introvertwhiz-ll2ip
@introvertwhiz-ll2ip 4 месяца назад
It worked thanks
@anujsharma5326
@anujsharma5326 Год назад
This is not working for me. I used the same code. However, I am not able to logged in to google.
@anujsharma5326
@anujsharma5326 Год назад
When I run the load cookies. It is navigated to google but no logged in. Please help me with the same. Thanks
@MichaelKitas
@MichaelKitas Год назад
Use user data dir instead
@akshatmalhotra6442
@akshatmalhotra6442 2 года назад
sir i wanted a code for changing proxies from a text file and checking proxies and then assign them to the undetected chromedriver
@MichaelKitas
@MichaelKitas 2 года назад
I will make a video on that soon 👍
@abogadosasesorias8848
@abogadosasesorias8848 9 месяцев назад
can we use this method to reuse the session on whatsapp web?
@MichaelKitas
@MichaelKitas 9 месяцев назад
Yeah, or you can use userDataDir as well
@uplifthabesha754
@uplifthabesha754 Год назад
Can you Please do a video on how to bypass DataDome anti-bot protection.
@MichaelKitas
@MichaelKitas Год назад
Will check it out and possibly make a video, thank you for the idea.
@rafaelhinojosa.
@rafaelhinojosa. Год назад
Excellent video! I But I got an error for 'invalid cookie domain' and tells me the session info. Do you know how can I fix this problem?
@MichaelKitas
@MichaelKitas Год назад
Thank you! You need to reuse cookies on the same domain you fetched them from. For example if you visited “google.com”, saved cookies then to reuse them you need to visit same domain “google.com”
@haroldabella2041
@haroldabella2041 2 года назад
How about multiple google chrome profile? Every time task was done it loads another chrome profile with the different google account
@MichaelKitas
@MichaelKitas 2 года назад
You can check my previous video (Ep 6) on how to use "User data directories" there you can specify your chrome profile and you can loop through all of them as you like
@anishasamant4042
@anishasamant4042 Год назад
For websites that required a one time sms code to login, at what point should the cookies be saved?
@MichaelKitas
@MichaelKitas Год назад
When you have successfully logged in
@vinnyvalentine5916
@vinnyvalentine5916 2 года назад
its loging me in but with limited access, I can go to google news, docs, slides, but when i try to go to gmail or youtube I'm redirected to a login page. Any advice?
@MichaelKitas
@MichaelKitas 2 года назад
Gmail uses a different domain for cookies, you can use a user data directory instead.
Год назад
Hi Vinny, did you solve this???
@vladislavberestenko5392
@vladislavberestenko5392 Год назад
Hi, thank you for your videos, they are very helpful. Is it safe to use Undetectable ChromeDriver to store my credentials and cookies?
@MichaelKitas
@MichaelKitas Год назад
Sure, though not sure what you mean by safe, that doesn't depend on the chromedriver itself.
@vladislavberestenko5392
@vladislavberestenko5392 Год назад
@@MichaelKitas I mean if I will use my main creds for gmail, etc, there is no way that undetectable driver can send them somewhere?
@MichaelKitas
@MichaelKitas Год назад
@@vladislavberestenko5392 It doesn't contain malware if that's what you mean
@vladislavberestenko5392
@vladislavberestenko5392 Год назад
@@MichaelKitas Thank you
@pabloaime
@pabloaime Год назад
Nice video, it works for me. My problem now is that I can just use the cookie once, if I try to reuse, it I will not login
@MichaelKitas
@MichaelKitas Год назад
It should, does it not work with a specific service?
Год назад
thank you very much, it works perfect. but if i want to go to youtube i am not logged in anymore, how can i do it?
@MichaelKitas
@MichaelKitas Год назад
Use userDataDir instead. Otherwise you are missing some cookies, you need to go to RU-vid.com after log in and get them as well and then load them to the same url
@MichaelKitas
@MichaelKitas Год назад
I might do a video on that since many people requested it
@xiangbingru6287
@xiangbingru6287 9 месяцев назад
Hi Michael. Great Tutorials. Do you have a way to pre-load cookies before sending the get request to the website? I tried to run the add cookies code before browser.get(). It shows invalid domain name. The reason i do this is this way behaves more like a human. 😂
@adeshinaibrahim9641
@adeshinaibrahim9641 8 месяцев назад
No, because you need to use the cookies on the domain you logged into, and now you haven't logged in so it doesn't recognize which domain(actually none) you are on.
@adeshinaibrahim9641
@adeshinaibrahim9641 8 месяцев назад
No, because you need to use the cookies on the domain you logged into, and now you haven't logged in so it doesn't recognize which domain(actually none) you are on.
@pubglovers6534
@pubglovers6534 2 года назад
Thanks for Tutorial But I have a question. How can we scrape data save in the database?
@MichaelKitas
@MichaelKitas 2 года назад
I have made episode 1,2,3 about how to scrape data, which you can combine with my MongoDB tutorial series: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-DjlXcwUQTMY.html
@pubglovers6534
@pubglovers6534 2 года назад
@@MichaelKitas ❤
@MiguelAndrade-f6d
@MiguelAndrade-f6d 7 месяцев назад
Hello, its possible to revoke all the cookies?
@MichaelKitas
@MichaelKitas 5 месяцев назад
Here’s the function for clearing cookies: async function clearCookies(page, cookieNames = []) { try { if (cookieNames.length === 0) { // Clearing all cookies await page.evaluate(() => { document.cookie.split(';').forEach((cookie) => { const name = cookie.split('=')[0].trim(); document.cookie = `${name}=; expires=Thu, 02 Jan 2024 00:00:00 UTC; path=/;`; }); }); } else { // Clearing specific cookies await page.deleteCookie(...cookieNames); } // Cookies have been cleared successfully return true; } catch (error) { // An error occurred while clearing cookies console.error('Error clearing cookies:', error); return false; } }
@CodeSomethingCrazy
@CodeSomethingCrazy Год назад
Whats the Theme name of your Vs Code
@MichaelKitas
@MichaelKitas Год назад
Bearded Theme - Arc
@yassinbousaadi1563
@yassinbousaadi1563 2 года назад
Thank you for the help, it's very appreciated. I still get captcha from the website I'm trying to scrap, but I don't know why. Is it a fair guess that a site would log my ip for some time to block me with a captcha every time I log in ?
@MichaelKitas
@MichaelKitas 2 года назад
Your welcome :) The captcha has probably to do with the IP address or it shows it either way. You can’t bypass captcha by reusing cookies. But I have made a video ep4 of this series on how to solve captchas automatically
@yassinbousaadi1563
@yassinbousaadi1563 2 года назад
@@MichaelKitas Well thank you for the quick reply. Actually, I went to my family's place with my laptop, and it does work without detecting anything. How funny. It's probably not the IP though, because I didn't switch proxies since I used this video 1 hour ago. So maybe restarting my computer can vscodium did activate the settings I took from your video ? I don't really know myself, I didn't change the actual scrapping code so that'll stay a mystery I guess.
@dimplejoshi7691
@dimplejoshi7691 2 года назад
sir can you tell about proxy rotation from txt
@MichaelKitas
@MichaelKitas 2 года назад
I will make a video on that soon 👍
@DealazonDaily
@DealazonDaily Год назад
Hey bro can you try to automate the facebook creator studio that was too hard to do while done everything the main problem comes in the schedule messages it was not able to scroll down. Can you please help me with that also many of us need like that, it would be helpful for us. Thank You
@MichaelKitas
@MichaelKitas Год назад
Not sure what scrolling issue you are referring to. How is this related to cookies?
@DealazonDaily
@DealazonDaily Год назад
@@MichaelKitas i am so sorry it was finished that work
@bebrightchannel6029
@bebrightchannel6029 2 года назад
How to multiple run browser profile spesifik ?
@MichaelKitas
@MichaelKitas 2 года назад
I am going to make a video on that soon
@bebrightchannel6029
@bebrightchannel6029 2 года назад
@@MichaelKitas thanks , i wait
@gdon80s
@gdon80s 2 года назад
How long can this reuse cookies be used to long in a website
@MichaelKitas
@MichaelKitas 2 года назад
Each cookie has they’re own expiration date, depends on how long they want the cookie to be working until you have to for example login again
@gdon80s
@gdon80s 2 года назад
@@MichaelKitas Hmm I see thank you
Далее
Cookie Handling For Selenium Web Scraping in Python
14:07
Angry bird PIZZA?
00:20
Просмотров 6 млн
Немного заблудился 😂
00:16
Просмотров 263 тыс.
15 Python Libraries You Should Know About
14:54
Просмотров 396 тыс.
Reuse cookies in Selenium with Python
8:47
Просмотров 32 тыс.
Automating My Bill Payments with Python and Selenium
1:18:30
This script I threw together saves me hours.
13:38
Просмотров 20 тыс.
Handle Cookies in Python Requests
13:50
Просмотров 11 тыс.
The Biggest Mistake Beginners Make When Web Scraping
10:21
Angry bird PIZZA?
00:20
Просмотров 6 млн