Python Selenium Tutorial #7 - Save & Reuse Cookies

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024

ความคิดเห็น • 80

  • @adarmawan117
    @adarmawan117 7 หลายเดือนก่อน +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!

  • @manoellevy7867
    @manoellevy7867 10 หลายเดือนก่อน +1

    you sir are a god amongst ants. ty

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

  • @softwareengineer8923
    @softwareengineer8923 ปีที่แล้ว +2

    This video helped me a lot,thanks!

  • @computernetworking6061
    @computernetworking6061 ปีที่แล้ว +2

    You saved my day bro, Great work!

  • @adscft7597
    @adscft7597 ปีที่แล้ว +1

    great work Michael!

  • @quangduydang299
    @quangduydang299 2 ปีที่แล้ว +1

    really awesome!!! here what I found many times

  • @introvertwhiz-ll2ip
    @introvertwhiz-ll2ip 3 หลายเดือนก่อน +1

    It worked thanks

  • @praveenverma2881
    @praveenverma2881 2 ปีที่แล้ว +1

    Awesome brother... Love your videos

  • @jw200
    @jw200 ปีที่แล้ว +1

    Perfect.
    I need it for my bot

  • @seanlee1577
    @seanlee1577 7 หลายเดือนก่อน +1

    It works! Thanks bro!

  • @MaahiVFX
    @MaahiVFX ปีที่แล้ว +1

    Thankyou it worked for me

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

  • @pastorjose9416
    @pastorjose9416 2 ปีที่แล้ว +1

    You saved my day . Thank you...

  • @vijayragavan839
    @vijayragavan839 ปีที่แล้ว +1

    Very Innovative

  • @shakils1921
    @shakils1921 ปีที่แล้ว +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  ปีที่แล้ว +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

  • @abogadosasesorias8848
    @abogadosasesorias8848 8 หลายเดือนก่อน +1

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

    • @MichaelKitas
      @MichaelKitas  8 หลายเดือนก่อน

      Yeah, or you can use userDataDir as well

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

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

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

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

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

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

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

  • @uplifthabesha754
    @uplifthabesha754 ปีที่แล้ว +1

    Can you Please do a video on how to bypass DataDome anti-bot protection.

    • @MichaelKitas
      @MichaelKitas  11 หลายเดือนก่อน

      Will check it out and possibly make a video, thank you for the idea.

  • @MiguelAndrade-f6d
    @MiguelAndrade-f6d 6 หลายเดือนก่อน +1

    Hello, its possible to revoke all the cookies?

    • @MichaelKitas
      @MichaelKitas  4 หลายเดือนก่อน

      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;
      }
      }

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

  • @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  11 หลายเดือนก่อน

      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

  •  ปีที่แล้ว +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 TH-cam.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

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

  • @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: th-cam.com/video/DjlXcwUQTMY/w-d-xo.html

    • @pubglovers6534
      @pubglovers6534 2 ปีที่แล้ว +2

      @@MichaelKitas ❤

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

  • @dimplejoshi7691
    @dimplejoshi7691 2 ปีที่แล้ว +1

    sir can you tell about proxy rotation from txt

    • @MichaelKitas
      @MichaelKitas  2 ปีที่แล้ว

      I will make a video on that soon 👍

  • @xiangbingru6287
    @xiangbingru6287 8 หลายเดือนก่อน +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 7 หลายเดือนก่อน +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 7 หลายเดือนก่อน +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.

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

  • @DealazonDaily
    @DealazonDaily ปีที่แล้ว +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  11 หลายเดือนก่อน +1

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

    • @DealazonDaily
      @DealazonDaily 11 หลายเดือนก่อน +1

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

  • @CodeSomethingCrazy
    @CodeSomethingCrazy ปีที่แล้ว +1

    Whats the Theme name of your Vs Code

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

  • @bebrightchannel6029
    @bebrightchannel6029 2 ปีที่แล้ว

    How to multiple run browser profile spesifik ?

  • @gdon80s
    @gdon80s ปีที่แล้ว

    How long can this reuse cookies be used to long in a website

    • @MichaelKitas
      @MichaelKitas  ปีที่แล้ว

      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 ปีที่แล้ว +1

      @@MichaelKitas Hmm I see thank you