|
@@ -1,5 +1,4 @@
|
|
|
import time
|
|
|
-import json
|
|
|
from selenium import webdriver
|
|
|
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
|
|
|
import time
|
|
@@ -11,16 +10,12 @@ 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 pymysql
|
|
|
-pymysql.install_as_MySQLdb()
|
|
|
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
table=db['general_log']
|
|
@@ -90,50 +85,39 @@ 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')
|
|
|
- options.add_argument('--remote-debugging-port='+str(q[2]))
|
|
|
-# options.add_experimental_option("debuggerAddress", "127.0.0.1:{q[2]}")
|
|
|
- options.add_argument("--user-agent=" +user_agent)
|
|
|
+ options.add_argument("--no-sandbox")
|
|
|
+ options.add_argument("--disable-dev-shm-usage")
|
|
|
+# options.add_argument("start-maximized")
|
|
|
+# 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("--incognito")
|
|
|
|
|
|
- driver = webdriver.Chrome(options=options,service=s)
|
|
|
-
|
|
|
+# driver = webdriver.Chrome(options=options,service=s)
|
|
|
+ print('before init')
|
|
|
+ driver = webdriver.Chrome(options=options)
|
|
|
+ print('after init')
|
|
|
+
|
|
|
driver.delete_all_cookies()
|
|
|
- driver.set_window_size(1400,1000)
|
|
|
+# driver.set_window_size(1400,1000)
|
|
|
|
|
|
print('到此')
|
|
|
process_query(q)
|
|
|
time.sleep(3)
|
|
|
driver.quit()
|
|
|
+ sys.exit()
|
|
|
|
|
|
|
|
|
-#for c in lst:
|
|
|
-#while True:
|
|
|
-# try:
|
|
|
-# c=random.choice(lst)
|
|
|
-# except:
|
|
|
-# traceback.print_exc()
|
|
|
-# sleepint=random.randint(320,520)
|
|
|
-# time.sleep(sleepint)
|
|
|
+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']
|
|
|
+ break
|
|
|
|
|
|
-class JParams(object):
|
|
|
-
|
|
|
- def get(self, kw,domain,port):
|
|
|
- print(kw)
|
|
|
- print(domain)
|
|
|
- run_once( (kw,domain,port) )
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- fire.Fire(JParams)
|
|
|
-
|
|
|
-
|
|
|
- def get(self, kw, domain, port):
|
|
|
- print('kw')
|
|
|
- print(domain)
|
|
|
- run_once((kw, domain, port))
|
|
|
+run_once((query,'hhh.com.tw'))
|
|
|
|