|
@@ -0,0 +1,55 @@
|
|
|
+import base64
|
|
|
+import os
|
|
|
+import time
|
|
|
+from time import sleep
|
|
|
+
|
|
|
+import numpy as np
|
|
|
+from PIL import Image
|
|
|
+from selenium import webdriver
|
|
|
+from selenium.webdriver.support import expected_conditions as EC
|
|
|
+from selenium.webdriver import ActionChains
|
|
|
+
|
|
|
+from selenium.webdriver.chrome.options import Options
|
|
|
+
|
|
|
+from selenium.common.exceptions import WebDriverException
|
|
|
+
|
|
|
+# 设置Chrome浏览器选项
|
|
|
+from selenium.webdriver.chrome.service import Service
|
|
|
+
|
|
|
+# 调用截图函数
|
|
|
+from selenium.webdriver.common.by import By
|
|
|
+from selenium.webdriver.support.wait import WebDriverWait
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ # 创建一个 Chrome WebDriver 实例
|
|
|
+ options = webdriver.ChromeOptions()
|
|
|
+ # options.add_argument("headless")
|
|
|
+ # options.add_argument(" window-size=1920,1080")
|
|
|
+ prefs = {'download.prompt_for_download': False, 'download.default_directory': '/Users/xiexiaoyuan/Downloads/'}
|
|
|
+ options.add_experimental_option('prefs', prefs)
|
|
|
+ s = Service(executable_path='/Users/xiexiaoyuan/chromedriver_mac64_111/chromedriver')
|
|
|
+ driver = webdriver.Chrome(service=s, options=options)
|
|
|
+ # driver.maximize_window()
|
|
|
+ driver.get('http://www.gfex.com.cn/gfex/rihq/hqsj_tjsj.shtml')
|
|
|
+ driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
|
|
|
+ "source": """
|
|
|
+ Object.defineProperty(navigator, 'webdriver', {
|
|
|
+ get: () => undefined
|
|
|
+ })
|
|
|
+ """
|
|
|
+ })
|
|
|
+ sleep(2)
|
|
|
+ WebDriverWait(driver, 10).until(
|
|
|
+ EC.element_to_be_clickable((By.XPATH, '//div[@id="tradeType"]/ul/li[1]/a'))).click()
|
|
|
+
|
|
|
+ sleep(5)
|
|
|
+ WebDriverWait(driver, 10).until(
|
|
|
+ EC.element_to_be_clickable((By.XPATH, '//button[@id="export_excel"]'))).click() # 点击导出excel
|
|
|
+
|
|
|
+ # b = driver.find_element(By.XPATH, '//button[@id="export_excel"]')
|
|
|
+ # print(b.text)
|
|
|
+ # b.click()
|
|
|
+ sleep(10)
|
|
|
+ # 等待文件下载完成
|
|
|
+ driver.implicitly_wait(10) # 等待10秒
|
|
|
+ driver.quit()
|