|  | @@ -0,0 +1,161 @@
 | 
											
												
													
														|  | 
 |  | +#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
 | 
											
												
													
														|  | 
 |  | +from userAgentRandomizer import userAgents
 | 
											
												
													
														|  | 
 |  | +import requests
 | 
											
												
													
														|  | 
 |  | +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)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +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:
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        r = redis.Redis(host='db.ptt.cx', port=6379, db=2,password='choozmo9')    
 | 
											
												
													
														|  | 
 |  | +        data=r.get('google_proxy')
 | 
											
												
													
														|  | 
 |  | +        jstext=data.decode('utf-8')
 | 
											
												
													
														|  | 
 |  | +        jsobj=json.loads(jstext)
 | 
											
												
													
														|  | 
 |  | +        print(jsobj)
 | 
											
												
													
														|  | 
 |  | +        proxy=random.choice(jsobj)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        ua = userAgents()
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        user_agent = ua.random()        
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        options = webdriver.ChromeOptions()
 | 
											
												
													
														|  | 
 |  | +        options.add_argument("--no-sandbox")
 | 
											
												
													
														|  | 
 |  | +        options.add_argument("--disable-dev-shm-usage")
 | 
											
												
													
														|  | 
 |  | +        options.add_argument("--headless")
 | 
											
												
													
														|  | 
 |  | +#        options.add_argument('--remote-debugging-port='+port)
 | 
											
												
													
														|  | 
 |  | +        options.add_argument('--proxy-server='+proxy)
 | 
											
												
													
														|  | 
 |  | +#        options.add_argument('--proxy-server=socks5://192.53.174.202:8180')
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#        options.add_argument('--proxy-server=%s' % proxy)
 | 
											
												
													
														|  | 
 |  | +        print(proxy)
 | 
											
												
													
														|  | 
 |  | +#        print('--proxy-server=%s' % proxy)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#        options.add_experimental_option("debuggerAddress", '127.0.0.1:9922')
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        print(user_agent)
 | 
											
												
													
														|  | 
 |  | +#        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.Remote(
 | 
											
												
													
														|  | 
 |  | +#                    executable_path='/root/drivers/102/chromedriver',
 | 
											
												
													
														|  | 
 |  | +#                    command_executor='http://0.0.0.0:4444/wd/hub',
 | 
											
												
													
														|  | 
 |  | +#                    options=options
 | 
											
												
													
														|  | 
 |  | + #               )
 | 
											
												
													
														|  | 
 |  | +#                driver = webdriver.Chrome(executable_path='/root/drivers/102/chromedriver',options=options)
 | 
											
												
													
														|  | 
 |  | +                driver = webdriver.Chrome(options=options)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        except:
 | 
											
												
													
														|  | 
 |  | +#            driver.quit()
 | 
											
												
													
														|  | 
 |  | +#            os.system('pkill -f ')
 | 
											
												
													
														|  | 
 |  | +#            os.system('kill %d' % os.getpid())
 | 
											
												
													
														|  | 
 |  | +            traceback.print_exc()
 | 
											
												
													
														|  | 
 |  | +            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
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#    i=random.randint(0,9)
 | 
											
												
													
														|  | 
 |  | +    i=100
 | 
											
												
													
														|  | 
 |  | +    if driver is None:
 | 
											
												
													
														|  | 
 |  | +        time.sleep(8)
 | 
											
												
													
														|  | 
 |  | +        re_get_webdriver()
 | 
											
												
													
														|  | 
 |  | +    if driver is None:
 | 
											
												
													
														|  | 
 |  | +        return
 | 
											
												
													
														|  | 
 |  | +    try:
 | 
											
												
													
														|  | 
 |  | +        kw=jsobj['kw']
 | 
											
												
													
														|  | 
 |  | +        if jsobj.get('domain') is None:
 | 
											
												
													
														|  | 
 |  | +            exclude=jsobj['exclude']
 | 
											
												
													
														|  | 
 |  | +            domain=None
 | 
											
												
													
														|  | 
 |  | +        else:
 | 
											
												
													
														|  | 
 |  | +            domain=jsobj['domain']
 | 
											
												
													
														|  | 
 |  | +            exclude=None
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#        driver.get('https://www.google.com?num=100')
 | 
											
												
													
														|  | 
 |  | +        driver.get('https://api.ipify.org/')
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        time.sleep(5)
 | 
											
												
													
														|  | 
 |  | +        print(driver.current_url)
 | 
											
												
													
														|  | 
 |  | +        elmt = driver.find_element(By.XPATH, "//body")
 | 
											
												
													
														|  | 
 |  | +        print(elmt.text)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    except:
 | 
											
												
													
														|  | 
 |  | +        print('exception')
 | 
											
												
													
														|  | 
 |  | +        traceback.print_exc()
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    driver.quit()
 | 
											
												
													
														|  | 
 |  | +    sys.exit()
 | 
											
												
													
														|  | 
 |  | +par1='tiny3'
 | 
											
												
													
														|  | 
 |  | +port='9942'
 | 
											
												
													
														|  | 
 |  | +#os.system('docker container restart tiny3')
 | 
											
												
													
														|  | 
 |  | +#time.sleep(8)
 | 
											
												
													
														|  | 
 |  | +#os.system('docker exec -it tiny3 curl --socks5 choozmo:choozmo9@172.105.205.52:8180 http://www.google.com')
 | 
											
												
													
														|  | 
 |  | +#p=random.choice(positive)
 | 
											
												
													
														|  | 
 |  | +run_once({'domain':'test','kw':" ttes"})
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +#run_once({'domain':domain,'kw':kw+' 錢濤'})
 | 
											
												
													
														|  | 
 |  | +
 |