鱼C论坛

 找回密码
 立即注册
查看: 3207|回复: 3

[作品展示] selenium刷在线时长脚本

[复制链接]
发表于 2023-4-20 22:33:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 歌者文明清理员 于 2023-5-2 23:57 编辑

因为需要10还是20分钟刷新一次fishccomcn才能计入在线时长
所以帮你们一把

  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from time import sleep
  4. from threading import Timer
  5. from lxml import html
  6. from re import sub, compile


  7. def timer():
  8.     Timer(10 * 60, flush).start()
  9.     Timer(5, time_long).start()


  10. def flush():
  11.     browser.refresh()
  12.     timer()


  13. def time_long():
  14.     browser.save_screenshot('space.png')
  15.     source = browser.page_source
  16.     tree = html.fromstring(source)
  17.     inline_time = tree.xpath(time)[0]
  18.     inline_time = html.tostring(inline_time, encoding='unicode')
  19.     inline_time_li = sub(compile(r'</?em>'), '', inline_time)
  20.     inline = sub(compile(r'(</?li>|</?em>|在线时间)'), '', inline_time_li)
  21.     print('在线时长:', inline)


  22. option = webdriver.ChromeOptions()
  23. option.add_argument('--headless')
  24. browser = webdriver.Chrome(options=option)
  25. url = 'https://fishc.com.cn/member.php?mod=logging&action=login'
  26. 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'
  27. 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'
  28. 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'
  29. 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'
  30. space = '/html/body/div[6]/div/div[1]/div/div/a'
  31. time = '/html/body/div[7]/div[4]/div/div[2]/div/div[1]/div[9]/ul[2]/li[1]'
  32. browser.get(url)
  33. sleep(1)
  34. browser.find_element(By.XPATH, username).send_keys('11')
  35. browser.find_element(By.XPATH, password).send_keys('11')
  36. browser.find_element(By.XPATH, autologin).click()
  37. browser.find_element(By.XPATH, submit).click()
  38. sleep(1)
  39. browser.find_element(By.ID, 'succeedmessage_href').click()
  40. sleep(0.1)
  41. browser.find_element(By.XPATH, space).click()
  42. sleep(1)
  43. timer()

复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-4-21 16:16:41 | 显示全部楼层
会被封
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-4-21 18:46:40 | 显示全部楼层
[b]小心了[/b]
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2023-11-14 15:52:52 From FishC Mobile | 显示全部楼层
感谢大佬的分享
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-24 08:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表