123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #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 random
- from selenium.webdriver.common.keys import Keys
- 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'])+'/')
- 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")
- chrome_options.add_argument("start-maximized")
- chrome_options.add_argument("user-data-dir=/tmp");
- chrome_options.debugger_address="127.0.0.1:9222"
- chrome98=r'C:\portable\webdriver\chrome98\chromedriver.exe'
- driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome98)
- driver.get('https://tw.yahoo.com/')
- time.sleep(5)
- #while True:
- for i in range(10):
- url=random.choice(lst)
- print(url)
- driver.get(url)
- # time.sleep(8)
- # driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
- # ActionChains(driver).key_down(Keys.CONTROL).send_keys('t').key_up(Keys.CONTROL).perform()
- # time.sleep(2)
- driver.execute_script('window.open("'+url+'","_blank");')
- driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
- time.sleep(8)
- # time.sleep(9999)
- #driver.save_screenshot('c:/tmp/sc.png')
|