You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# pip install selenium
# 下载ChromeDriver
from selenium import webdriver
from selenium . webdriver . common . by import By
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
# 设置 WebDriver 路径(这里以 Chrome 为例)
chrome_driver_path = ' C: \ Windows \ System32 \ chromedriver.exe '
# 打开目标网页
url = " http://10.10.14.203/#/de-link/NtXhclS0 "
# 初始化 WebDriver
options = webdriver . ChromeOptions ( )
# 设置为无头模式
options . add_argument ( ' --headless ' )
driver = webdriver . Chrome ( options = options )
# 打开目标网页
driver . get ( url )
# 设置显式等待
wait = WebDriverWait ( driver , 1000 )
# 等待页面的 readyState 为 complete
wait . until ( lambda driver : driver . execute_script ( " return document.readyState " ) == " complete " )
# 或者等待 Vue 应用的特定条件,比如 Vue 实例的变量
# 假设 Vue 应用中有一个全局变量 vueAppReady, 当页面渲染完成时被设置为 true
wait . until ( lambda driver : driver . execute_script ( " return window.vueAppReady " ) == True )
# 或者等待页面上的某个特定文本出现,这个文本必须在页面渲染完成后才会出现
text_to_wait_for = ' Text that appears when the page is fully rendered '
wait . until ( EC . text_to_be_present_in_element ( ( By . TAG_NAME , ' body ' ) , text_to_wait_for ) )
# 执行你需要的操作,比如抓取数据
page_source = driver . page_source
# 关闭浏览器
driver . quit ( )
# 处理页面源代码或其他操作
print ( page_source )