selenium刷在线时长脚本
本帖最后由 歌者文明清理员 于 2023-5-2 23:57 编辑因为需要10还是20分钟刷新一次fishccomcn才能计入在线时长
所以帮你们一把
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from threading import Timer
from lxml import html
from re import sub, compile
def timer():
Timer(10 * 60, flush).start()
Timer(5, time_long).start()
def flush():
browser.refresh()
timer()
def time_long():
browser.save_screenshot('space.png')
source = browser.page_source
tree = html.fromstring(source)
inline_time = tree.xpath(time)
inline_time = html.tostring(inline_time, encoding='unicode')
inline_time_li = sub(compile(r'</?em>'), '', inline_time)
inline = sub(compile(r'(</?li>|</?em>|在线时间)'), '', inline_time_li)
print('在线时长:', inline)
option = webdriver.ChromeOptions()
option.add_argument('--headless')
browser = webdriver.Chrome(options=option)
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'
space = '/html/body/div/div/div/div/div/a'
time = '/html/body/div/div/div/div/div/div/div/ul/li'
browser.get(url)
sleep(1)
browser.find_element(By.XPATH, username).send_keys('11')
browser.find_element(By.XPATH, password).send_keys('11')
browser.find_element(By.XPATH, autologin).click()
browser.find_element(By.XPATH, submit).click()
sleep(1)
browser.find_element(By.ID, 'succeedmessage_href').click()
sleep(0.1)
browser.find_element(By.XPATH, space).click()
sleep(1)
timer()
会被封 小心了{:10_334:} 感谢大佬的分享
页:
[1]