12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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=['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')
- driver = webdriver.Chrome(
- desired_capabilities=options.to_capabilities())
- driver.set_window_size(1400,1000)
- for i in range(3):
- l=random.choice(lst)
- # driver.get("https://www.hhh.com.tw/cases/detail/"+l+"/index.php")
- driver.get(l)
- print(driver.current_url)
- driver.execute_script("window.scrollTo(0, window.scrollY + 200)")
- # driver.implicitly_wait (2)
- time.sleep(6)
- driver.quit()
|