compact_remote.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #import redis
  2. import time
  3. import traceback
  4. #import json
  5. from selenium import webdriver
  6. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  7. import time
  8. import os
  9. from selenium.webdriver.support.ui import WebDriverWait
  10. from selenium.webdriver.common.by import By
  11. from selenium.webdriver.support import expected_conditions as EC
  12. from selenium.webdriver.common.action_chains import ActionChains
  13. import dataset
  14. import rpyc
  15. import random
  16. from selenium.webdriver.common.keys import Keys
  17. from userAgentRandomizer import userAgents
  18. lst=[]
  19. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  20. #os.system("docker container restart headless-shell")
  21. #time.sleep(6)
  22. cursor=db.query('SELECT * FROM columnids order by rand()')
  23. for c in cursor:
  24. lst.append('https://www.hhh.com.tw/columns/detail/'+str(c['cid'])+'/')
  25. servers=[{'port':'10922','name':'tiny1'},{'port':'10924','name':'tiny2'},{'port':'10926','name':'tiny3'}]
  26. server=random.choice(servers)
  27. print(server)
  28. try:
  29. conn = rpyc.classic.connect('192.168.192.9', port = 18812)
  30. except:
  31. print('exception')
  32. ros=conn.modules.os
  33. ros.system('docker container restart '+server['name'])
  34. time.sleep(7)
  35. chrome_options = webdriver.ChromeOptions()
  36. chrome_options.add_argument("--incognito")
  37. chrome_options.add_argument("--headless")
  38. chrome_options.add_argument("--no-sandbox")
  39. chrome_options.add_argument("--disable-dev-shm-usage")
  40. ua = userAgents()
  41. user_agent = ua.random()
  42. chrome_options.add_argument("start-maximized")
  43. chrome_options.add_argument("user-data-dir=/tmp")
  44. chrome_options.add_argument("--user-agent=" +user_agent)
  45. chrome_options.debugger_address="192.168.192.9:"+server['port']
  46. #chrome98=r'C:\portable\webdriver\chrome98\chromedriver.exe'
  47. chrome98=r'/root/drivers/98/chromedriver'
  48. driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome98)
  49. #while True:
  50. for i in range(12):
  51. url=random.choice(lst)
  52. print(url)
  53. # driver.get(url)
  54. driver.execute_script('window.open("'+url+'","_blank");')
  55. driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
  56. # time.sleep(0.2)