Python Selenium Tutorial #7 - Save & Reuse Cookies

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024

Комментарии • 80

  • @adarmawan117
    @adarmawan117 8 месяцев назад +2

    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 Год назад +3

    Awesome tutorial, this is the first method I've found that actually works!

  • @javovsci
    @javovsci 2 года назад +1

    BRO, I FUCKING LOVE YOU, YOU SAVED ALL MY WORK AND HELPED ME A LOT. I LOVE YOU!!! THANKS FOR THAT VIDEO!!!

  • @manoellevy7867
    @manoellevy7867 11 месяцев назад +1

    you sir are a god amongst ants. ty

  • @adscft7597
    @adscft7597 Год назад +1

    great work Michael!

  • @javiergonzalez7207
    @javiergonzalez7207 Год назад +1

    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?

  • @softwareengineer8923
    @softwareengineer8923 Год назад +2

    This video helped me a lot,thanks!

  • @computernetworking6061
    @computernetworking6061 Год назад +2

    You saved my day bro, Great work!

  • @shakils1921
    @shakils1921 2 года назад +1

    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 года назад +1

      Maybr create a script which saves cookies after a specific timeout, within that timeout login manually while of course you are using the script

  • @aminatawillane3437
    @aminatawillane3437 2 года назад +1

    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?

  • @akshatmalhotra6442
    @akshatmalhotra6442 2 года назад +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

  • @bhavanakedari1009
    @bhavanakedari1009 Год назад +1

    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

  • @vijayragavan839
    @vijayragavan839 Год назад +1

    @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

  • @vladislavberestenko5392
    @vladislavberestenko5392 Год назад +1

    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  Год назад +1

      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  Год назад +1

      @@vladislavberestenko5392 It doesn't contain malware if that's what you mean

    • @vladislavberestenko5392
      @vladislavberestenko5392 Год назад

      @@MichaelKitas Thank you

  • @quangduydang299
    @quangduydang299 2 года назад +1

    really awesome!!! here what I found many times

  • @praveenverma2881
    @praveenverma2881 2 года назад +1

    Awesome brother... Love your videos

  • @rafaelhinojosa.
    @rafaelhinojosa. Год назад +1

    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”

  • @jw200
    @jw200 Год назад +1

    Perfect.
    I need it for my bot

  • @xiangbingru6287
    @xiangbingru6287 10 месяцев назад +1

    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 месяцев назад +1

      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 месяцев назад +1

      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.

  • @seanlee1577
    @seanlee1577 8 месяцев назад +1

    It works! Thanks bro!

  • @vijayragavan839
    @vijayragavan839 Год назад +1

    Very Innovative

  • @MaahiVFX
    @MaahiVFX Год назад +1

    Thankyou it worked for me

  • @vinnyvalentine5916
    @vinnyvalentine5916 2 года назад +1

    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???

  • @anishasamant4042
    @anishasamant4042 Год назад +1

    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

  • @akshatmalhotra6442
    @akshatmalhotra6442 2 года назад +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 👍

  • @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.

  • @abogadosasesorias8848
    @abogadosasesorias8848 9 месяцев назад +1

    can we use this method to reuse the session on whatsapp web?

    • @MichaelKitas
      @MichaelKitas  9 месяцев назад

      Yeah, or you can use userDataDir as well

  •  Год назад +1

    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 RUclips.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

  • @haroldabella2041
    @haroldabella2041 2 года назад +1

    How about multiple google chrome profile? Every time task was done it loads another chrome profile with the different google account

    • @MichaelKitas
      @MichaelKitas  2 года назад +1

      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

  • @introvertwhiz-ll2ip
    @introvertwhiz-ll2ip 5 месяцев назад +1

    It worked thanks

  • @pubglovers6534
    @pubglovers6534 2 года назад +1

    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: ruclips.net/video/DjlXcwUQTMY/видео.html

    • @pubglovers6534
      @pubglovers6534 2 года назад +2

      @@MichaelKitas ❤

  • @anujsharma5326
    @anujsharma5326 Год назад +1

    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  Год назад +1

      Use user data dir instead

  • @pabloaime
    @pabloaime Год назад +1

    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?

  • @pastorjose9416
    @pastorjose9416 2 года назад +1

    You saved my day . Thank you...

  • @uplifthabesha754
    @uplifthabesha754 Год назад +1

    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.

  • @mastermanhwas
    @mastermanhwas Год назад +1

    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  Год назад +1

      Not sure what scrolling issue you are referring to. How is this related to cookies?

    • @mastermanhwas
      @mastermanhwas Год назад +1

      @@MichaelKitas i am so sorry it was finished that work

  • @MiguelAndrade-f6d
    @MiguelAndrade-f6d 8 месяцев назад +1

    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 Год назад +1

    Whats the Theme name of your Vs Code

  • @dimplejoshi7691
    @dimplejoshi7691 2 года назад +1

    sir can you tell about proxy rotation from txt

    • @MichaelKitas
      @MichaelKitas  2 года назад

      I will make a video on that soon 👍

  • @bebrightchannel6029
    @bebrightchannel6029 2 года назад

    How to multiple run browser profile spesifik ?

  • @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 года назад +1

      @@MichaelKitas Hmm I see thank you