selenium查看是否有新提醒
本帖最后由 歌者文明清理员 于 2023-3-19 16:17 编辑代码
# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
url = 'https://fishc.com.cn/member.php?mod=logging&action=login'
username = '/html/body/div/div/div/div/div/div/div/form/div/div/table/tbody/tr/td/input'
password = '/html/body/div/div/div/div/div/div/div/form/div/div/table/tbody/tr/td/input'
submit = '/html/body/div/div/div/div/div/div/div/form/div/div/table/tbody/tr/td/button'
autologin = '/html/body/div/div/div/div/div/div/div/form/div/div/table/tbody/tr/td/label/input'
option = webdriver.ChromeOptions()
option.add_argument('headless') # 如果不想隐藏窗口注释这行
browser = webdriver.Chrome(options=option)
browser.get(url)
sleep(1)
browser.find_element(By.XPATH, username).send_keys('用户名')# 用户名
browser.find_element(By.XPATH, password).send_keys('密码') # 密码
browser.find_element(By.XPATH, autologin).click()
browser.find_element(By.XPATH, submit).click()
sleep(6)
yes = False
for i in range(6):
if '【新提醒】' in browser.title:
yes = True
sleep(0.5)
if yes:
print('有新提醒!')
else:
print('没有')
browser.close()
配置:链接太长啦
selenium 指南:我想想这个链接起啥名咧
把 20 行到 28 行放进 while True 里就可以自动检测啦
页:
[1]