log4j只是日志框架接口,slf4j以及logback都实现了这个类,所以都有你上面的class,在加载的时候包名和类名完全一样就会上面的提示,你安装下maven help插件,搜索下对应冲突包,排除下应该就行
from selenium import webdriver
import time
up_names = ['up1', 'up2', 'up3']
driver = webdriver.Chrome('C:/chromedriver_win32/chromedriver.exe')
driver.get('passport.bilibili.com/l')
time.sleep(5) # 需要等待页面加载完毕才能操作
username = driver.find_element_by_name('username')
password = driver.find_element_by_name('password')
submit = driver.find_element_by_xpath('//button[@class="btn btn-login"]')
username.send_keys('your_username') # 输入你的 B 站账号
password.send_keys('your_password') # 输入你的 B 站密码
submit.click()
time.sleep(5) # 需要等待页面加载完毕才能操作
for up_name in up_names:
driver.get(f'space.bilibili.com/{up_name}/')
time.sleep(2)
follow_button = driver.find_element_by_xpath('//div[@class="n-gz-btn"]')
if follow_button.get_attribute('class') == 'n-gz-btn n-gz-btn-cancel':
follow_button.click()
confirm_button = driver.find_element_by_xpath('//div[@class="z-msgbox a-bouncein"]//button[text()="确认"]')
confirm_button.click()
time.sleep(2)
print(f'已取消关注 {up_name}')
driver.quit()
问题分析:
这里主要分析错误日志信息中的以下3点~
1.LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. 得知日志jar包冲突
2.Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/E:/IT_zhengqing/soft/soft-dev/Maven/repository-zhengqing/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar). 提示排除Logback或与其冲突包的实现slf4j-log4j
3.If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory 提示如果需要使用WebLogic则添加org.slf4j相关依赖
解决方法:通过maven插件Maven Helper来实现排除冲突~
pom.xml -> Dependency Analyzer -> 搜索slf4j-log4j -> 右击选择Exclude将其冲突依赖排除
望采纳!!!