Jared %!s(int64=2) %!d(string=hai) anos
pai
achega
b9978af355
Modificáronse 2 ficheiros con 157 adicións e 0 borrados
  1. 117 0
      INNNews/general_remote_click.py
  2. 40 0
      INNNews/routine_click.py

+ 117 - 0
INNNews/general_remote_click.py

@@ -0,0 +1,117 @@
+import time
+import json
+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.support import expected_conditions as EC
+import codecs
+import random
+import requests
+import datetime
+import dataset
+import time
+import traceback
+import sys
+import fire
+#from INNNews import notifytest
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+table=db['general_log']
+
+
+  
+driver=None
+headers = {
+        "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+
+
+def send_msg(kw):
+    params = {"message": "處理關鍵字: "+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):
+    q=qs[0]
+    domain=qs[1]
+    global driver
+    googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(urllib.parse.quote(q), 100,'zh-TW')
+    print(googleurl)
+    driver.get(googleurl)
+    time.sleep(6)
+
+    elmts=driver.find_elements(By.XPATH,"//div[@class='yuRUbf']/a")
+
+    idx=1
+    ranking=-1
+    print(len(elmts))
+#    driver.save_screenshot('c:/tmp/test.png')
+
+    for elmt in elmts:
+
+        href=elmt.get_attribute('href')
+        txt=elmt.text
+        if len(txt)>10:
+            if domain in href:
+                print('clicked....')
+                print(href)
+                print(txt)
+                print("ranking", idx)
+                table.insert({'kw':q,'domain':domain,'ranking':idx,'title':txt,'url':href,'dt':datetime.datetime.now()})
+                webdriver.ActionChains(driver).move_to_element(elmt).perform()
+                webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+                break
+        idx+=1
+
+def run_once(q):
+    global driver
+    result=[]
+    options = webdriver.ChromeOptions()
+    options.add_argument('--headless')
+
+    options.add_argument('--disable-dev-shm-usage')
+    options.add_argument('--no-sandbox')
+#    options.add_argument('--remote-debugging-port=9222')
+
+
+#    options.add_experimental_option("debuggerAddress", "192.168.192.45:9922")
+    options.add_experimental_option("debuggerAddress", q[2])
+
+#    options.add_argument("--user-agent=" +user_agent)
+    options.add_argument("--incognito")
+
+#    driver = webdriver.Chrome(executable_path=r'C:\portable\webdriver\chrome98\chromedriver.exe',options=options)
+    driver = webdriver.Chrome(executable_path=q[3],options=options)
+
+    driver.delete_all_cookies()
+    driver.set_window_size(1400,1000)
+
+    print(q)
+    process_query(q)
+    time.sleep(3)
+    driver.quit()
+
+class JParams(object):
+
+  def get(self, kw,domain,address,epath):
+    print(kw)
+    print(domain)
+    run_once( (kw,domain,address,epath)   )
+
+
+if __name__ == '__main__':
+  fire.Fire(JParams)
+

+ 40 - 0
INNNews/routine_click.py

@@ -0,0 +1,40 @@
+import time
+import json
+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.support import expected_conditions as EC
+import codecs
+import random
+import requests
+import datetime
+import dataset
+import time
+import traceback
+import sys
+import fire
+#from INNNews import notifytest
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+term=None
+domain='hhh.com.tw'
+address="192.168.192.45:9922"
+cursor=db.query('SELECT term FROM seo.selected_kw where client = "hhh" order by rand() limit 1')
+for c in cursor:
+    term=c['term']
+    break
+
+if os.name == 'nt':
+    py='python'
+else:
+    py='python3'
+
+
+
+os.system(py+' general_remote_click.py get --kw="'+term+'" --domain='+domain+' --address="'+address+'"')
+
+