|
@@ -18,18 +18,27 @@ import time
|
|
|
import traceback
|
|
|
import sys
|
|
|
import fire
|
|
|
-import pymysql
|
|
|
-pymysql.install_as_MySQLdb()
|
|
|
-from ig_tags import setting
|
|
|
+#import pymysql
|
|
|
+#pymysql.install_as_MySQLdb()
|
|
|
+
|
|
|
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
table=db['general_log']
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
driver = None
|
|
|
|
|
|
|
|
|
+def rua():
|
|
|
+ pool = [
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0",
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36",
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
|
|
|
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.125",
|
|
|
+ ]
|
|
|
+ return random.choice(pool)
|
|
|
+
|
|
|
|
|
|
def empty_query(q):
|
|
|
global driver
|
|
@@ -47,7 +56,7 @@ def process_query(qs):
|
|
|
driver.get(googleurl)
|
|
|
time.sleep(6)
|
|
|
|
|
|
- elmts=driver.find_elements(By.T,"//div[@class='yuRUbf']/a")
|
|
|
+ elmts=driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
|
|
|
|
|
|
idx=1
|
|
|
ranking=-1
|
|
@@ -74,11 +83,11 @@ def run_once(q):
|
|
|
global driver
|
|
|
result=[]
|
|
|
s = Service('/root/driver/chromedriver')
|
|
|
- user_agent = setting.rua()
|
|
|
+ user_agent = rua()
|
|
|
options = webdriver.ChromeOptions()
|
|
|
options.add_argument('--headless')
|
|
|
options.add_argument('--remote-debugging-port=9222')
|
|
|
- options.add_experimental_option("debuggerAddress", "127.0.0.1:9922")
|
|
|
+ options.add_experimental_option("debuggerAddress", f"127.0.0.1:{q[2]}")
|
|
|
options.add_argument("--user-agent=" +user_agent)
|
|
|
options.add_argument("--incognito")
|
|
|
|
|
@@ -105,10 +114,9 @@ def run_once(q):
|
|
|
|
|
|
class JParams(object):
|
|
|
|
|
|
- def get(self, kw,domain):
|
|
|
- print('kw')
|
|
|
- print(domain)
|
|
|
- run_once( (kw,domain) )
|
|
|
+ def get(self, kw,domain,port):
|
|
|
+ print('關鍵字',kw)
|
|
|
+ run_once( (kw,domain,port) )
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|