|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 歌者文明清理员 于 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)[0]
- 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[6]/div/div[2]/div/div[2]/div[1]/div[1]/form/div/div[1]/table/tbody/tr/td[1]/input'
- password = '/html/body/div[6]/div/div[2]/div/div[2]/div[1]/div[1]/form/div/div[2]/table/tbody/tr/td[1]/input'
- submit = '/html/body/div[6]/div/div[2]/div/div[2]/div[1]/div[1]/form/div/div[6]/table/tbody/tr/td[1]/button'
- autologin = '/html/body/div[6]/div/div[2]/div/div[2]/div[1]/div[1]/form/div/div[5]/table/tbody/tr/td/label/input'
- space = '/html/body/div[6]/div/div[1]/div/div/a'
- time = '/html/body/div[7]/div[4]/div/div[2]/div/div[1]/div[9]/ul[2]/li[1]'
- 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()
复制代码 |
|