12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #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
- import json
- import random
- import time
- import sys
- import codecs
- import random
- import os
- import time
- driver=None
- def re_get_webdriver():
- global driver
- result=[]
- # client = docker.from_env()
- # ls=client.containers.list()
- # print(ls)
- # for l in ls:
- # if 'p17777' in l.name:
- # ls[0].restart()
- # time.sleep(4)
- if driver is not None:
- print('closing....')
- driver.quit()
- # options = webdriver.EdgeOptions()
- try:
- options = webdriver.ChromeOptions()
- options.add_argument("--no-sandbox")
- options.add_argument("--disable-dev-shm-usage")
- options.add_argument("--headless")
- driver = webdriver.Chrome(options=options)
- # desired_capabilities=options.to_capabilities())
- driver.set_window_size(1400,1000)
- return
- except:
- import traceback
- traceback.print_exc()
- driver=None
- return None
- driver=None
- def run_once(url):
- global driver
- i=random.randint(0,15)
- if i==0 or driver is None:
- # if True:
- re_get_webdriver()
- time.sleep(3)
- if driver is None:
- return
- try:
- driver.execute_script('window.open("'+url+'","_blank");')
- driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
- time.sleep(0.5)
- except:
- print('exception')
- lst=[]
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
- 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'])+'/index.php')
- #lst=['https://www.hhh.com.tw/columns/detail/3427/index.php']
- #for i in range(20):
- while True:
- l=random.choice(lst)
- print(l)
- run_once(l)
|