全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 3887|回复: 23

[疑问] Online特价机监控源码,需要的拿去吧

[复制链接]
发表于 2017-8-2 12:18:06 | 显示全部楼层 |阅读模式
本来想弄一个7Ohdd的,可惜没上,一步到位买了个20O的。
不提供任何技术支持,有疑问的可以跟帖,请勿私信或者加QQ询问使用方法 谢谢。
  1. import re
  2. import time
  3. import requests
  4. from datetime import datetime
  5. from bs4 import BeautifulSoup
  6. from selenium import webdriver
  7. from selenium.webdriver.common.keys import Keys


  8. prices = ['6.99', '16.99', '19.99']
  9. check_interval = 60
  10. keys = [
  11.     '你的Server酱的key',
  12.     '其他的Server酱的key',
  13. ]
  14. timeout = 20
  15. notified = {}
  16. notice_times = 5
  17. driver = None


  18. def check_special_offer():
  19.     try:
  20.         if not driver:
  21.             start_driver()
  22.         driver.get('https://www.online.net/en/summer-2017/sales')
  23.         sid = driver.find_elements_by_name('server_offer')[0]
  24.         driver.execute_script("arguments[0].setAttribute('value','10010')", sid)
  25.         sid.submit()
  26.         html = driver.page_source
  27.         soup = BeautifulSoup(html, 'html.parser')
  28.         trs = soup.find_all('tr')
  29.         for tr in trs:
  30.             tds = tr.find_all('td')
  31.             if tds and tds[-1].find('form'):
  32.                 tds_text = [td.text for td in tds]
  33.                 price = tds_text[-2].replace(' € pre-tax', '').strip()
  34.                 details = '\n\n'.join(tds_text[:-1])
  35.                 if price in prices:
  36.                     if notified.get(price, 0) < notice_times:
  37.                         send_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  38.                         text = '{}O有货啦'.format(price)
  39.                         desp = details + '\n\n' + send_time
  40.                         notified[price] = notified.get(price, 0) + 1
  41.                         print('{}O有货了,第{}次通知'.format(price, notified[price]))
  42.                         for key in keys:
  43.                             send_message(key, text, desp)
  44.                             time.sleep(1)
  45.                     else:
  46.                         print('{}O的相关信息超过最大通知次数,不再微信通知...'.format(price))
  47.                 else:
  48.                     notified.setdefault(price, 0)
  49.     except Exception as e:
  50.         print(e)
  51.         pass
  52.             

  53. def send_message(key, text, desp = ''):
  54.     url = 'https://sc.ftqq.com/{}.send'.format(key)
  55.     data = {
  56.         'text': text,
  57.         'desp': desp
  58.     }
  59.     r = requests.post(url, data = data, timeout = timeout)


  60. def start_driver():
  61.     global driver
  62.     chromeOptions = webdriver.ChromeOptions()
  63.     prefs = {
  64.         "profile.managed_default_content_settings.images": 2,
  65.         'profile.managed_default_content_settings.javascript': 2
  66.     }
  67.     chromeOptions.add_experimental_option("prefs", prefs)
  68.     driver = webdriver.Chrome(chrome_options = chromeOptions)
  69.     # service_args=[]
  70.     # service_args.append('--load-images=no')  ##关闭图片加载
  71.     # service_args.append('--disk-cache=yes')  ##开启缓存
  72.     # service_args.append('--ignore-ssl-errors=true') ##忽略https错误
  73.     # service_args.append('--ignore-ssl-errors=true')
  74.     # service_args.append('--ssl-protocol=TLSv1')
  75.     # cap = webdriver.DesiredCapabilities.PHANTOMJS
  76.     # cap["phantomjs.page.settings.javascriptEnabled"] = False
  77.     # driver = webdriver.PhantomJS(desired_capabilities = cap, service_args = service_args)
  78.     driver.implicitly_wait(timeout)
  79.     driver.set_page_load_timeout(timeout)




  80. def main():
  81.     while True:
  82.         try:
  83.             check_special_offer()
  84.             print('{}秒后再次检查,当前时间: {}'.format(check_interval, datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
  85.             time.sleep(check_interval)
  86.         except Exception as e:
  87.             print(e)
  88.             pass


  89. if __name__ == '__main__':
  90.     main()

复制代码
发表于 2017-8-2 12:22:02 | 显示全部楼层
大神出现了。。……………………
发表于 2017-8-2 12:40:14 | 显示全部楼层
这怎么用的啊?
 楼主| 发表于 2017-8-2 12:43:11 | 显示全部楼层

给ps个护照呗,我教你怎么用
1. 安装python3.x
2. 安装依赖:pip install requests selenium beautisoup4
3. 下载chromedriver
4. 添加你自己的微信通知的key
5. python online.py
6. 完了
 楼主| 发表于 2017-8-2 12:43:32 | 显示全部楼层

见楼上
发表于 2017-8-2 12:45:29 | 显示全部楼层
谢谢大神分享
发表于 2017-8-2 12:58:13 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2017-8-2 13:23:39 | 显示全部楼层
cdwyd 发表于 2017-8-2 12:43
给ps个护照呗,我教你怎么用
1. 安装python3.x
2. 安装依赖:pip install requests selenium beauti ...

厉害啊 你买了几台
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-10-7 07:23 , Processed in 0.061748 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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