|
@@ -1,4 +1,5 @@
|
|
|
import time
|
|
|
+import json
|
|
|
from selenium import webdriver
|
|
|
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
|
|
|
import time
|
|
@@ -10,14 +11,17 @@ from selenium.webdriver.chrome.service import Service
|
|
|
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
|
|
|
import random
|
|
|
-import socket
|
|
|
-import requests
|
|
|
+import pymysql
|
|
|
+pymysql.install_as_MySQLdb()
|
|
|
+
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
table=db['general_log']
|
|
|
|
|
@@ -42,15 +46,6 @@ def rua():
|
|
|
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)
|
|
@@ -78,8 +73,8 @@ def process_query(qs):
|
|
|
idx=1
|
|
|
ranking=-1
|
|
|
print('搜尋結果數量',len(elmts))
|
|
|
- if len(elmts) <=0:
|
|
|
- send_msg('network failed...')
|
|
|
+ # if len(elmts) <=0:
|
|
|
+ # send_msg('network failed...')
|
|
|
# driver.save_screenshot('c:/tmp/test.png')
|
|
|
|
|
|
for elmt in elmts:
|
|
@@ -101,11 +96,12 @@ def process_query(qs):
|
|
|
def run_once(q):
|
|
|
global driver
|
|
|
result=[]
|
|
|
-# s = Service('/root/driver/chromedriver')
|
|
|
+ s = Service('/root/driver/chromedriver')
|
|
|
# s = Service('/Users/zooeytsai/Downloads/chromedriver 2')
|
|
|
user_agent = rua()
|
|
|
options = webdriver.ChromeOptions()
|
|
|
options.add_argument('--headless')
|
|
|
+<<<<<<< HEAD
|
|
|
options.add_argument("--no-sandbox")
|
|
|
options.add_argument("--disable-dev-shm-usage")
|
|
|
### options.add_argument("--proxy-server=socks5://192.168.192.156:1080")
|
|
@@ -115,15 +111,17 @@ def run_once(q):
|
|
|
# options.add_argument('--remote-debugging-port='+str(q[2]))
|
|
|
# options.add_argument('--remote-debugging-port=9222')
|
|
|
# options.add_argument("--user-agent=" +user_agent)
|
|
|
+=======
|
|
|
+ options.add_argument('--remote-debugging-port=9222')
|
|
|
+ options.add_experimental_option("debuggerAddress", "127.0.0.1:{q[2]}")
|
|
|
+ options.add_argument("--user-agent=" +user_agent)
|
|
|
+>>>>>>> a9354c3cc90b2f2f084e5b4ee374041dbeeb0217
|
|
|
options.add_argument("--incognito")
|
|
|
|
|
|
-# driver = webdriver.Chrome(options=options,service=s)
|
|
|
- print('before init')
|
|
|
- driver = webdriver.Chrome(options=options)
|
|
|
- print('after init')
|
|
|
-
|
|
|
+ driver = webdriver.Chrome(options=options,service=s)
|
|
|
+
|
|
|
driver.delete_all_cookies()
|
|
|
-# driver.set_window_size(1400,1000)
|
|
|
+ driver.set_window_size(1400,1000)
|
|
|
|
|
|
print('到此')
|
|
|
process_query(q)
|
|
@@ -131,12 +129,15 @@ def run_once(q):
|
|
|
driver.quit()
|
|
|
sys.exit()
|
|
|
|
|
|
-cursor = db.query('SELECT query FROM seo.hhh_gsc_imp where position >=2.5 and position <=8.5 order by rand() limit 1')
|
|
|
-query=None
|
|
|
-for c in cursor:
|
|
|
- query=c['query']
|
|
|
- print(query)
|
|
|
- break
|
|
|
|
|
|
-run_once((query,'hhh.com.tw'))
|
|
|
+class JParams(object):
|
|
|
+
|
|
|
+ def get(self, kw, domain, port):
|
|
|
+ print(kw)
|
|
|
+ print(domain)
|
|
|
+ run_once((kw, domain, port))
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ fire.Fire(JParams)
|
|
|
|