Преглед изворни кода

Merge remote-tracking branch 'origin/master'

zooeytsai пре 3 година
родитељ
комит
8b2d1f27d9
3 измењених фајлова са 160 додато и 17 уклоњено
  1. 11 16
      hhh/SEO/fast_1999.py
  2. 144 0
      hhh/SEO/hhh_port_edge.py
  3. 5 1
      ig_tags/ig_selenium.py

+ 11 - 16
hhh/SEO/fast_1999.py

@@ -21,7 +21,7 @@ import codecs
 import random
 import os
 import time
-
+import dataset
 
 driver=None
 headers = {
@@ -91,7 +91,10 @@ def re_get_webdriver():
 #    time.sleep(4)
     if driver is not None:
         print('closing....')
-        driver.quit()
+#        driver.quit()
+        os.system('docker container restart p'+portnum)
+        time.sleep(11)
+        
 #    options = webdriver.EdgeOptions()
     try:
         driver = webdriver.Remote(
@@ -107,11 +110,10 @@ def re_get_webdriver():
 
 def run_once(url):
     global driver
-    i=random.randint(0,15)
+    i=random.randint(0,25)
     if i==0 or driver is None:
 #    if True:
         re_get_webdriver()
-        time.sleep(3)
     if driver is None:
         return
     try:
@@ -132,26 +134,19 @@ def run_once(url):
 
 portnum=sys.argv[1]
 
-fpath=__file__
-elmts=fpath.split('\\')
-fpath=fpath.replace(elmts[-1],'urls.csv')
-
 os.system('docker restart p'+str(portnum))
 time.sleep(4)
 
 
 
+lst=[]
 
-print(fpath)
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
 
-lst=[]
+cursor=db.query('SELECT * FROM columnids order by rand()')
+for c in cursor:
+    lst.append('https://www.hhh.com.tw/columns/detail/'+str(c['cid'])+'/index.php')
 
-fr=codecs.open(fpath,'r','utf-8')
-lines=fr.readlines()
-for l in lines:
-    elmts=l.split(',')
-    lst.append('https://www.hhh.com.tw'+elmts[0])
-fr.close()
 
 #lst=['https://www.hhh.com.tw/columns/detail/3427/index.php']
     #for i in range(20):

+ 144 - 0
hhh/SEO/hhh_port_edge.py

@@ -0,0 +1,144 @@
+#import redis
+import time
+import traceback
+#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 time
+import sys
+import docker
+import codecs
+import random
+import os
+import time
+import dataset
+
+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[2]
+    cnt=qs[1]
+    global driver
+    googleurl='https://www.google.com/search?q='+urllib.parse.quote(q)
+    driver.get(googleurl)
+    time.sleep(3)
+    if cnt > 0:
+        for i in range(cnt):
+            elmt=driver.find_element_by_xpath("//a[@id='pnnext']")
+            webdriver.ActionChains(driver).move_to_element(elmt).perform()
+            webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+    time.sleep(3)
+
+
+
+    elmts=driver.find_elements_by_xpath("//div[@class='g']//div[@class='yuRUbf']//a")
+    idx=1
+    ranking=-1
+    for elmt in elmts:
+        href=elmt.get_attribute('href')
+        txt=elmt.text
+        if len(txt)>10:
+#            if 'hhh.com.tw' in href:
+#            if 'hhh.com.tw' in href:
+#            if 'ai.choozmo.com' in href:
+            if domain in href:
+#            if 'searchome.net' in href:
+                webdriver.ActionChains(driver).move_to_element(elmt).perform()
+                webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+                break
+
+
+def re_get_webdriver():
+    global driver
+    result=[]
+    client = docker.from_env()
+    ls=client.containers.list()
+    print(ls)
+    for l in ls:
+        if 'p'+portnum in l.name:
+            ls[0].restart()
+
+    time.sleep(4)
+#    if driver is not None:
+#        driver.close()
+#    options = webdriver.EdgeOptions()
+    try:
+        driver = webdriver.Remote(
+            command_executor='http://127.0.0.1:'+portnum+'/wd/hub')
+        driver.set_window_size(1400,1000)
+        return
+    except:
+        import traceback
+        traceback.print_exc()
+        driver=None
+        return None
+    driver=None
+
+def run_once(url):
+    global driver
+    i=random.randint(0,20)
+    if i<=3 or driver is None:
+#    if True:
+        re_get_webdriver()
+        time.sleep(3)
+    if driver is None:
+        return
+    try:
+        driver.execute_script('window.open("'+url+'","_blank");')
+        driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
+        time.sleep(1)
+    except:
+        print('exception')
+
+portnum=sys.argv[1]
+
+
+lst=[]
+
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+
+cursor=db.query('SELECT * FROM columnids order by rand()')
+for c in cursor:
+    lst.append('https://www.hhh.com.tw/columns/detail/'+str(c['cid'])+'/index.php')
+
+
+#lst=['https://www.hhh.com.tw/columns/detail/3427/index.php']
+    #for i in range(20):
+while True:
+    l=random.choice(lst)
+    print(l)
+#    driver.get(l)
+    run_once(l)
+#    time.sleep(2)
+
+

+ 5 - 1
ig_tags/ig_selenium.py

@@ -16,8 +16,12 @@ import ast
 import pymysql
 
 pymysql.install_as_MySQLdb()
+
 import pd
-from setting import rua
+import setting
+
+
+account = ['chenlinrain','enjoylisteningswift','novak_goodenough']
 
 account = pd.account
 password = pd.password