1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #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
- from selenium.webdriver.common.action_chains import ActionChains
- import dataset
- import rpyc
- import random
- from selenium.webdriver.common.keys import Keys
- from userAgentRandomizer import userAgents
- lst=[]
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
- #os.system("docker container restart headless-shell")
- #time.sleep(6)
- cursor=db.query('SELECT * FROM columnids order by rand()')
- for c in cursor:
- lst.append('https://www.hhh.com.tw/columns/detail/'+str(c['cid'])+'/')
- servers=[{'port':'10922','name':'tiny1'},{'port':'10924','name':'tiny2'},{'port':'10926','name':'tiny3'}]
- server=random.choice(servers)
- print(server)
- try:
- conn = rpyc.classic.connect('192.168.192.9', port = 18812)
- except:
- print('exception')
- ros=conn.modules.os
- ros.system('docker container restart '+server['name'])
- time.sleep(7)
- chrome_options = webdriver.ChromeOptions()
- chrome_options.add_argument("--incognito")
- chrome_options.add_argument("--headless")
- chrome_options.add_argument("--no-sandbox")
- chrome_options.add_argument("--disable-dev-shm-usage")
- ua = userAgents()
- user_agent = ua.random()
- chrome_options.add_argument("start-maximized")
- chrome_options.add_argument("user-data-dir=/tmp")
- chrome_options.add_argument("--user-agent=" +user_agent)
- chrome_options.debugger_address="192.168.192.9:"+server['port']
- #chrome98=r'C:\portable\webdriver\chrome98\chromedriver.exe'
- chrome98=r'/root/drivers/98/chromedriver'
- driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome98)
- #while True:
- for i in range(12):
- url=random.choice(lst)
- print(url)
- # driver.get(url)
- driver.execute_script('window.open("'+url+'","_blank");')
- driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
- # time.sleep(0.2)
|