Browse Source

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/kw_tools

Jared 2 năm trước cách đây
mục cha
commit
c01ab43bde

+ 0 - 120
website_clickjobs/clickjob.py

@@ -1,120 +0,0 @@
-import time
-from datetime import datetime
-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 dataset
-import traceback
-import sys
-
-target_domain=['bennis.com.tw']
-brands={'bennis.com.tw':'班尼斯'}
-
-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")
-    # ABOVE METHOD IS DEPRECATED STARTING SELENIUM 4.3.0, USE THIS
-    elmts=driver.find_elements("xpath","//div[@class='yuRUbf']/a")
-
-    idx=1
-    ranking=-1
-    domain_in_link = 0
-
-    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:
-                domain_in_link += 1
-                print('clicked....')
-                print(href)
-                print(txt)
-                webdriver.ActionChains(driver).move_to_element(elmt).perform()
-                webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
-                break
-    
-    if domain in target_domain:
-        print("Target domain found")
-        time_stamp = datetime.fromtimestamp(time.time())
-        time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
-        db['query_results'].insert({"time_stamp": time_stamp, "brand": brands[domain], "domain": domain, "query": q, "googleurl": googleurl, "element_count": len(elmts), "domain_in_link_count": domain_in_link})
-
-def run_once(q):
-    global driver
-    result=[]
-    options = webdriver.ChromeOptions()
-    options.add_argument('--headless')
-#    options.add_argument("--user-agent=" +user_agent)
-    options.add_argument("--incognito")
-    options.add_argument('--no-sandbox')
-    options.add_argument('--disable-dev-shm-usage')
-
-    driver = webdriver.Chrome(
-    options=options)
-
-    driver.delete_all_cookies()
-    driver.set_window_size(1400,1000)
-
-    print(q)
-    process_query(q)
-    time.sleep(3)
-    driver.quit()
-
-#lst=[{'kw':'幸福空間','domain':'hhh.com.tw','page':0}]
-lst=[]
-db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
-
-cursor=db.query('select term,domain from selected_kw order by rand()')
-
-for c in cursor:
-    lst.append(c)
-
-
-#for c in lst:
-while True:
-    try:
-        c=random.choice(lst)
-        run_once( (c['term'],c['domain'])   )
-    except:
-        traceback.print_exc()
-    sleepint=random.randint(20,40)
-    time.sleep(sleepint)

+ 37 - 21
website_clickjobs/bennisclickjob.py → website_clickjobs/type-1/_clickjob.py

@@ -17,16 +17,16 @@ import traceback
 import sys
 from selenium.webdriver.common.keys import Keys
 
-target_domain=['bennis.com.tw']
-brands={'bennis.com.tw':'班尼斯'}
+add_tabs = [4,5,6,7,8,4,5,6,7,8,4,5,6,7,8,4,5,6,7,8]
 
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
 driver=None
 headers = {
         "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
         "Content-Type": "application/x-www-form-urlencoded"
 }
 
-
+sleepoffset = 0
 
 def send_msg(kw):
     params = {"message": "處理關鍵字: "+kw}  
@@ -40,9 +40,9 @@ def empty_query(q):
     time.sleep(3)
 
 
-def process_query():
-    q="班尼斯"
-    domain="bennis.com.tw"
+def process_query(domain, target_domain, brands, query):
+    print(query)
+    sleepoffset = 0
     global driver
     driver.get('https://www.google.com?num=100')
     time.sleep(3)
@@ -54,7 +54,7 @@ def process_query():
     elmt = driver.find_element(By.XPATH, "//input[@name='q']")
     time.sleep(1)
 
-    elmt.send_keys(q)
+    elmt.send_keys(query)
     elmt.send_keys(Keys.ENTER)
 
     idx=1
@@ -80,26 +80,40 @@ def process_query():
                 print(txt)
                 webdriver.ActionChains(driver).move_to_element(el).perform()
                 webdriver.ActionChains(driver).move_to_element(el).click().perform()
-                time.sleep(6)
+                time.sleep(15)
+
+                new_windows_count = add_tabs[random.randint(0,19)]
+                print(str(new_windows_count) + " new tabs")
+                for i in range (0,new_windows_count):
+                    print("Tab" + str(i+1))
+                    #original_window = driver.current_window_handle
+                    #driver.switch_to.new_window('window')
+                    #driver.get(href)
+                    sleepoffset += 12
+                    driver.execute_script('window.open("'+href+'","_blank");')
+                    driver.execute_script("window.scrollTo(0, 600)")
+                    time.sleep(15)
+                    #driver.close()
+                    #driver.switch_to.window(original_window)
 
                 if domain in target_domain:
                     print("Target link found")
                     time_stamp = datetime.fromtimestamp(time.time())
                     time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
-                    db['click_results'].insert({"time_stamp": time_stamp, "brand": brands[domain], "domain": domain, "query": q, "url": href, "content": txt})
+                    db['click_results'].insert({"time_stamp": time_stamp, "brand": brands[domain], "domain": domain, "query": query, "url": href, "content": txt, "extra_windows": new_windows_count})
                 break
 
     if domain in target_domain:
         print("Target domain found")
         time_stamp = datetime.fromtimestamp(time.time())
         time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
-        db['query_results'].insert({"time_stamp": time_stamp, "brand": brands[domain], "domain": domain, "query": q, "googleurl": googleurl, "element_count": len(elmts), "domain_in_link_count": domain_in_link})
+        db['query_results'].insert({"time_stamp": time_stamp, "brand": brands[domain], "domain": domain, "query": query, "googleurl": googleurl, "element_count": len(elmts), "domain_in_link_count": domain_in_link})
             
 
     print(domain_in_link)
     
 
-def run_once():
+def run_once(domain, target_domain, brands, query):
     global driver
     result=[]
     options = webdriver.ChromeOptions()
@@ -115,18 +129,20 @@ def run_once():
     driver.delete_all_cookies()
     driver.set_window_size(1400,1000)
 
-    process_query()
+    process_query(domain, target_domain, brands, query)
     time.sleep(3)
     driver.quit()
 
 #execution starts here
-db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
 
-while True:
-    try:
-        run_once()
-    except:
-        traceback.print_exc()
-    sleepint=random.randint(35,50)
-    print("Completed (" + str(sleepint) + ")")
-    time.sleep(sleepint)
+def execute(domain, target_domain, brands, query_list):
+    while True:
+        try:
+            run_once(domain, target_domain, brands, random.choice(query_list))
+        except:
+            traceback.print_exc()
+        sleepint = random.randint(75,90)
+        sleepint = sleepint - sleepoffset
+        print("Completed (" + str(sleepint) + ")")
+        if sleepint > 0:
+            time.sleep(sleepint)

+ 8 - 0
website_clickjobs/type-1/bennis.py

@@ -0,0 +1,8 @@
+from _clickjob import *
+
+domain = 'bennis.com.tw'
+target_domain = ['bennis.com.tw']
+brands={domain:'班尼斯'}
+query_list = ('班尼斯', '乳膠 墊 推薦', '床 墊 訂 做 價格', '乳膠 床 推薦')
+
+execute(domain, target_domain, brands, query_list)

+ 8 - 0
website_clickjobs/type-1/yogoclean.py

@@ -0,0 +1,8 @@
+from _clickjob import *
+
+domain = 'yogoclean.com'
+target_domain = ['yogoclean.com']
+brands={domain:'有夠讚'}
+query_list = ('有夠讚','有夠讚')
+
+execute(domain, target_domain, brands, query_list)

BIN
website_clickjobs/type-2/__pycache__/_clickjob.cpython-39.pyc


+ 81 - 0
website_clickjobs/type-2/_clickjob.py

@@ -0,0 +1,81 @@
+import time
+from datetime import datetime
+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 dataset
+import traceback
+import sys
+from selenium.webdriver.common.keys import Keys
+
+add_tabs = [4,5,6,7,8,4,5,6,7,8,4,5,6,7,8,4,5,6,7,8]
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+driver=None
+headers = {
+        "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+sleepoffset = 0
+
+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(target):
+    print(target)
+    global driver
+    driver.get(target)
+    print(driver.current_url)
+    time.sleep(15)
+
+
+def run_once(target):
+    global driver
+    result=[]
+    options = webdriver.ChromeOptions()
+    options.add_argument('--headless')
+#    options.add_argument("--user-agent=" +user_agent)
+    options.add_argument("--incognito")
+    options.add_argument('--no-sandbox')
+    options.add_argument('--disable-dev-shm-usage')
+
+    driver = webdriver.Chrome(
+    options=options)
+
+    driver.delete_all_cookies()
+    driver.set_window_size(1400,1000)
+
+    process_query(target)
+    time.sleep(3)
+    driver.quit()
+
+#execution starts here
+
+def execute(target):
+    while True:
+        try:
+            run_once(target)
+        except:
+            traceback.print_exc()
+        sleepint = 10
+        print("Completed")
+        time.sleep(sleepint)

+ 5 - 0
website_clickjobs/type-2/bennis.py

@@ -0,0 +1,5 @@
+from _clickjob import *
+
+target = 'https://www.bennis.com.tw'
+
+execute(target)

+ 5 - 0
website_clickjobs/type-2/yogoclean.py

@@ -0,0 +1,5 @@
+from _clickjob import *
+
+target = 'https://www.yogoclean.com'
+
+execute(target)