Jason 2 лет назад
Родитель
Сommit
c23b485165
1 измененных файлов с 138 добавлено и 0 удалено
  1. 138 0
      website_clickjobs/tools/resetrouter.py

+ 138 - 0
website_clickjobs/tools/resetrouter.py

@@ -0,0 +1,138 @@
+import time
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+import time
+import os
+import urllib.parse
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.common.by import By
+from selenium.webdriver.chrome.service import Service
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.common.keys import Keys
+#import schedule
+import codecs
+import random
+import datetime
+import dataset
+import time
+import traceback
+import sys
+import random
+import socket
+import requests
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+table=db['general_log']
+
+
+driver = None
+headers = {
+        "Authorization": "Bearer " + "6SDULL1Ebklduc6TFxa97AFto5Sj21kyJ30CxiLiSoi",
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+def scrolling(driver,pgnum):
+    ub = driver.find_element_by_css_selector('body')
+    for i in range(pgnum):
+        ub.send_keys(Keys.PAGE_DOWN)
+        if pgnum>1:
+            time.sleep(0.3)
+
+
+
+def rua():
+    pool = [
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0",
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36",
+        "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
+        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.125",
+    ]
+    return random.choice(pool)
+
+
+
+
+def send_msg(kw):
+    hname=socket.gethostname()
+    params = {"message": hname+": "+kw}  
+    r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
+
+
+
+def empty_query(q):
+    global driver
+    googleurl='https://www.google.com/search?q='+urllib.parse.quote(q)
+    driver.get(googleurl)
+    time.sleep(3)
+
+
+def process_query(qs):
+    global driver
+#    googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(urllib.parse.quote(q), 100,'zh-TW')
+    googleurl = 'http://192.168.0.1/index.html'
+
+    print(googleurl)
+    driver.get(googleurl)
+    time.sleep(6)
+#    time.sleep(9999)id="pc-login-password"
+    try:
+        elmt = driver.find_element(By.XPATH, "//a[@data-localize='menu.system']")
+        webdriver.ActionChains(driver).move_to_element(elmt).perform()
+        webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+        time.sleep(5)
+        elmt = driver.find_element(By.XPATH, "//a[@data-localize='system_popup.settings_profile_left_tab']")
+        webdriver.ActionChains(driver).move_to_element(elmt).perform()
+        webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+        time.sleep(5)
+        elmt = driver.find_element(By.XPATH, "//input[@data-localize='system_popup.reboot']")
+        webdriver.ActionChains(driver).move_to_element(elmt).perform()
+        webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+        time.sleep(5)
+        elmt = driver.find_element(By.XPATH, "//button[contains(text(),'確定')]")
+        webdriver.ActionChains(driver).move_to_element(elmt).perform()
+        webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+        time.sleep(5)
+    except:
+        traceback.print_exc()
+    driver.quit()
+    sys.exit()
+
+    return "ok"
+
+
+def run_once():
+    global driver
+    result=[]
+    user_agent = rua()
+    options = webdriver.ChromeOptions()
+    options.add_argument('--headless')
+    options.add_argument("--no-sandbox")
+    options.add_argument("--disable-dev-shm-usage")
+    options.add_argument("--incognito")
+    print('before init')
+    os.system('taskkill /f /im msedge.exe')
+    os.system('taskkill /f /im chrome.exe')
+    driver = webdriver.Chrome(options=options)
+    print('after init')
+ 
+    driver.delete_all_cookies()
+    driver.set_window_size(1400,1000)
+#    driver.set_window_size(900, 3000)
+    print('到此')
+    data=process_query('')
+    if data is not None:
+        time.sleep(3)
+    driver.quit()
+
+
+
+#  /mnt/c/Windows/System32/cmd.exe /C python c:/gitlab/test/reboot.py
+#schedule.every(21).minutes.do(run_once)
+
+while True: 
+   run_once()
+   time.sleep(900)
+   
+