|
@@ -0,0 +1,152 @@
|
|
|
|
+#import redis
|
|
|
|
+import time
|
|
|
|
+import traceback
|
|
|
|
+#import json
|
|
|
|
+from selenium import webdriver
|
|
|
|
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
|
|
|
|
+import time
|
|
|
|
+import os
|
|
|
|
+from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
+from selenium.webdriver.common.by import By
|
|
|
|
+from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
+import dataset
|
|
|
|
+from selenium.webdriver.common.keys import Keys
|
|
|
|
+import json
|
|
|
|
+import random
|
|
|
|
+import time
|
|
|
|
+import redis
|
|
|
|
+import sys
|
|
|
|
+import codecs
|
|
|
|
+import random
|
|
|
|
+import os
|
|
|
|
+import time
|
|
|
|
+import requests
|
|
|
|
+from time import sleep
|
|
|
|
+#from wrapt_timeout_decorator import *
|
|
|
|
+driver=None
|
|
|
|
+
|
|
|
|
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
|
|
|
|
+
|
|
|
|
+headers = {
|
|
|
|
+ "Authorization": "Bearer " + "6SDULL1Ebklduc6TFxa97AFto5Sj21kyJ30CxiLiSoi",
|
|
|
|
+ "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)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#@timeout(20)
|
|
|
|
+def re_get_webdriver():
|
|
|
|
+ global port
|
|
|
|
+ global driver
|
|
|
|
+ result=[]
|
|
|
|
+ if driver is not None:
|
|
|
|
+ print('closing....')
|
|
|
|
+ driver.quit()
|
|
|
|
+ os.system('killall chrome')
|
|
|
|
+ print('quit....')
|
|
|
|
+ driver=None
|
|
|
|
+ try:
|
|
|
|
+ options = webdriver.ChromeOptions()
|
|
|
|
+ options.add_argument("--no-sandbox")
|
|
|
|
+ options.add_argument("--disable-dev-shm-usage")
|
|
|
|
+# options.add_argument("--headless")
|
|
|
|
+# options.add_argument('--proxy-server='+proxy)
|
|
|
|
+# options.add_argument('--proxy-server=socks5://172.104.93.163:41800')
|
|
|
|
+
|
|
|
|
+# options.add_argument('--proxy-server=socks5://127.0.0.1:9050')
|
|
|
|
+# options.add_argument('--proxy-server=%s' % proxy)
|
|
|
|
+# print('--proxy-server=%s' % proxy)
|
|
|
|
+# options.add_experimental_option("debuggerAddress", '127.0.0.1:9922')
|
|
|
|
+# options.add_argument("--user-agent=" +user_agent)
|
|
|
|
+ options.add_argument("--incognito")
|
|
|
|
+ driver=None
|
|
|
|
+ try:
|
|
|
|
+# driver = webdriver.Chrome(options=options)
|
|
|
|
+ if os.name=='nt':
|
|
|
|
+ driver = webdriver.Chrome(executable_path='C:/portable/webdriver/chrome102/chromedriver.exe',options=options)
|
|
|
|
+ else:
|
|
|
|
+ driver = webdriver.Chrome(options=options)
|
|
|
|
+ except:
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+
|
|
|
|
+ driver.quit()
|
|
|
|
+ sys.exit()
|
|
|
|
+ return
|
|
|
|
+ driver.set_window_size(1400,1000)
|
|
|
|
+ return
|
|
|
|
+ except:
|
|
|
|
+ traceback.print_exc()
|
|
|
|
+ driver=None
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def run_once(jsobj):
|
|
|
|
+
|
|
|
|
+ table=db['rank_detection']
|
|
|
|
+ print(jsobj)
|
|
|
|
+ global driver
|
|
|
|
+ kw=jsobj['kw']
|
|
|
|
+
|
|
|
|
+ i=100
|
|
|
|
+ if driver is None:
|
|
|
|
+ re_get_webdriver()
|
|
|
|
+ if driver is None:
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+ driver.get('https://news.google.com/topstories?hl=zh-TW&gl=TW&ceid=TW:zh-Hant')
|
|
|
|
+
|
|
|
|
+ time.sleep(5)
|
|
|
|
+
|
|
|
|
+ elmt = driver.find_element(By.XPATH, "//input[contains(@aria-label,'搜尋')]")
|
|
|
|
+ print(elmt)
|
|
|
|
+
|
|
|
|
+ time.sleep(1)
|
|
|
|
+ elmt.send_keys(kw)
|
|
|
|
+ elmt.send_keys(Keys.ENTER)
|
|
|
|
+ time.sleep(7)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ elmts = driver.find_elements(By.XPATH, "//main//div[@class='xrnccd']//article/a[contains(@href,'./articles/')]")
|
|
|
|
+ print(len(elmts))
|
|
|
|
+ elmt=elmts[-1]
|
|
|
|
+ print(elmt)
|
|
|
|
+ webdriver.ActionChains(driver).move_to_element(elmt).perform()
|
|
|
|
+ webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
|
|
|
|
+ time.sleep(8)
|
|
|
|
+ driver.quit()
|
|
|
|
+ sys.exit()
|
|
|
|
+par1='tiny3'
|
|
|
|
+port='9942'
|
|
|
|
+os.system('killall chrome')
|
|
|
|
+#os.system('docker container restart proxy1')
|
|
|
|
+time.sleep(8)
|
|
|
|
+#os.system('curl --socks5 choozmo:choozmo9@172.104.93.163:41800 http://www.google.com')
|
|
|
|
+time.sleep(3)
|
|
|
|
+
|
|
|
|
+r=random.randint(0,1)
|
|
|
|
+r=2
|
|
|
|
+if r==0:
|
|
|
|
+ prefix="site:hhh.com.tw "
|
|
|
|
+ domain=['hhh.com.tw']
|
|
|
|
+ positive=['北歐 風格 定義','','房 間隔 局','小 房間 設計','裝潢 費用','室內 裝修','設計 公司','透 天 裝潢','鄉村 風 裝潢']
|
|
|
|
+elif r==1:
|
|
|
|
+ prefix="site:gs-rack.com "
|
|
|
|
+ domain=['gs-rack.com']
|
|
|
|
+ positive=['神助','移動模組','移動貨架','無軌道','創新設計','專利移動櫃','重型架','物流設備','客戶實績','儲存方案','客戶服務','平台移動','重型電動','分離式','重型移動','冷庫重型移動','防爆倉','專利移動模組','輕中型移動貨架','傳統後推','少量多樣','大量少樣','重型貨品']
|
|
|
|
+elif r==2:
|
|
|
|
+ prefix="錢濤 "
|
|
|
|
+ postfix=' site:ltn.com.tw'
|
|
|
|
+ domain=['ltn.com.tw']
|
|
|
|
+ positive=['對沖基金','俄烏戰爭','美國升息']
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+kw=random.choice(positive)
|
|
|
|
+run_once({'domain':domain,'kw':prefix+kw+postfix})
|
|
|
|
+
|
|
|
|
+
|