python - 分享绕过验证码登录的方法
一、通过webdriver启动浏览器:
二、添加cookie:
三、切换到目标地址:
# This is a sample Python script. from selenium import webdriver import time # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. def print_hi(name): # Use a breakpoint in the code line below to debug your script. # print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. driver=webdriver.Chrome() driver.get("默认地址") time.sleep(3) # print(driver.get_cookies()) c1 ={'domain': '.mail.qq.com', 'expiry': 1760776980, 'httpOnly': False, 'name': 'webp', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1'} c2 ={'domain': '.mail.qq.com', 'expiry': 1731832978, 'httpOnly': False, 'name': 'CCSHOW', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '000000'} driver.add_cookie(c1) driver.add_cookie(c2) time.sleep(1) driver.get("目标地址") time.sleep(5) # Press the green button in the gutter to run the script. if __name__ == '__main__': print_hi('PyCharm') # See PyCharm help at https://www.jetbrains.com/help/pycharm/