themoo.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.service import Service
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.common.keys import Keys
  5. import time
  6. def scrolling(driver, pgnum):
  7. ub = driver.find_element("css selector",'body')
  8. for i in range(pgnum):
  9. ub.send_keys(Keys.PAGE_DOWN)
  10. if pgnum > 1:
  11. time.sleep(0.3)
  12. def process_query():
  13. global driver
  14. url = 'https://hhh.com.tw/HHH_NEW/designers/index_designerList.php?cid=807'
  15. driver.get(url)
  16. print('這裡')
  17. time.sleep(3)
  18. print(driver.current_url)
  19. scrolling(driver, 1)
  20. time.sleep(3)
  21. elmt = driver.find_element(By.XPATH,'/html/body/div[2]/section[3]/div/div[1]/div/div[3]/div[1]/aside[6]/div[2]')
  22. driver.maximize_window()
  23. webdriver.ActionChains(driver).move_to_element(elmt).perform()
  24. webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
  25. time.sleep(6)
  26. driver.quit()
  27. def run_once():
  28. global driver
  29. result = []
  30. user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
  31. s = Service('C:\/Users\/s1301\/Downloads\/chromedriver_110\/chromedriver')
  32. options = webdriver.ChromeOptions()
  33. # options.add_argument('--headless')
  34. # options.add_argument('--remote-debugging-port=9222')
  35. # options.add_experimental_option("debuggerAddress", "192.168.192.45:9922")
  36. options.add_argument("--user-agent=" + user_agent)
  37. options.add_argument("--incognito")
  38. # options.add_argument('--proxy-server=socks5://172.104.93.163:41800')
  39. driver = webdriver.Chrome(
  40. options=options, service=s)
  41. process_query()
  42. time.sleep(3)
  43. driver.quit()
  44. count = 0
  45. while count<6:
  46. try:
  47. run_once()
  48. count+=1
  49. except:
  50. pass