Using selenium login pan.baidu.com with cookie

we relsoved two issues in this code:

  1. login with cookie
  2. close the popup window after login.
    here is the code:

    import requests
    import time
    from selenium import webdriver
    PATH = "C:\Program Files\chromedriver.exe"
    driver = webdriver.Chrome(PATH)
    url = "https://pan.baidu.com/disk/home#/all?path=%2F&vmode=list"
    driver.get(url)
    cookies = {
    "BDUSS": "your_BDUSS",
    "STOKEN": "your_STOKEN",
    "domain": "pan.baidu.com"
    }
    response_cookies_browser = [{'name':name, 'value':value} for name, value in cookies.items()]
    c = [driver.add_cookie(c) for c in response_cookies_browser]
    #the browser now contains the cookies generated from the authentication    
    driver.get(url)
    #wait 10 seconds for the popup window, so we can click the close button 
    time.sleep(10)
    driver.find_elements_by_xpath('.//span[@class = "dialog-icon dialog-close icon icon-close"]')[-1].click()

Leave a Reply

Your email address will not be published. Required fields are marked *