自动化模块
自动登录自动点击
from selenium import webdriver
from webdriver_manager. microsoft import EdgeChromiumDriverManager
from selenium. webdriver. edge. service import Service
import time
from selenium. webdriver. common. by import By
try :
service = Service( EdgeChromiumDriverManager( ) . install( ) )
driver = webdriver. Edge( service= service)
driver. maximize_window( )
driver. get( "请求地址" )
time. sleep( 2 )
account = driver. find_element( By. ID, '登录' )
account. send_keys( '用户名' )
time. sleep( 2 )
password = driver. find_element( By. ID, '密码' )
password. send_keys( '密码' )
time. sleep( 2 )
driver. find_element( By. ID, '登录按钮' ) . click( )
time. sleep( 15 )
driver. find_element( By. XPATH, '登录按钮' ) . click( )
time. sleep( 2 )
driver. find_element( By. ID, '登录按钮' ) . click( )
homePage = driver. current_window_handle
time. sleep( 2 )
count = 0
while count < 100 :
driver. find_element( By. XPATH, '代点击元素' ) . click( )
window_handles = driver. window_handles
website2_handle = None
for handle in window_handles:
if handle != homePage:
website2_handle = handle
break
driver. switch_to. window( website2_handle)
time. sleep( 1 )
count += 1
driver. close( )
driver. switch_to. window( homePage)
time. sleep( 10 )
except Exception as e:
print ( f"An error occurred: { e} " )
自动登录点赞收藏