1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- from selenium import webdriver
- import time
- import random
- import codecs
- fpath=__file__
- fpath=fpath.replace('hhh_phantom.py','urls.csv')
- print(fpath)
- lst=[]
- fr=codecs.open(fpath,'r','utf-8')
- lines=fr.readlines()
- for l in lines:
- elmts=l.split(',')
- lst.append('https://www.hhh.com.tw'+elmts[0])
- fr.close()
- #lst=['https://www.hhh.com.tw/cases/detail/d/13051/index.php','https://www.hhh.com.tw/columns/detail/5878/index.php']
- #lst=['13781','3649','2116']
- #for i in range(9999):
- if True:
- options = webdriver.ChromeOptions()
- # options.add_argument('--headless')
- options.add_argument('--disable-gpu') # Last I checked this was necessary.
- # options.add_argument('--incognito')
- options.add_argument('--no-sandbox')
- options.add_argument('--disable-dev-shm-usage')
- options.add_argument('--user-data-dir=C:\\tmp\\user')
- driver = webdriver.Chrome(
- desired_capabilities=options.to_capabilities())
- driver.set_window_size(1400,1000)
- for i in range(10):
- l=random.choice(lst)
- # driver.get("https://www.hhh.com.tw/cases/detail/"+l+"/index.php")
- # driver.get(l)
- driver.execute_script('window.open("'+l+'","_blank");')
- print(driver.current_url)
- time.sleep(4)
- driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
- time.sleep(2)
- # driver.implicitly_wait (2)
- time.sleep(5)
- driver.quit()
|