有兩個el-table-box,它與v-if = & quot;!特殊聲明& quot,另一個與v-if = & quot;特殊聲明& quot,如何用css選擇器定位第一個?
我寫作
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
# Configure Chrome options for headless mode
chrome_options = Options()
chrome_options.add_argument("--headless") # Enable headless mode
# Set path to chromedriver executable
chromedriver_path = '/path/to/chromedriver' # Replace with your actual path
# Create a new instance of the Chrome driver
driver = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)
# Navigate to the desired web page
url ="http://www.cninfo.com.cn/new/commonUrl/pageOfSearch?url=disclosure/list/search"
driver.get(url) # Replace with the actual URL of the page
# Find the parent div element
parent_div = driver.find_element(By.CSS_SELECTOR, 'div.el-table-box[v-if="!specialAnnounce"]')
然后我得到一個nosuchelementexception
TimeoutException Traceback (most recent call last)
Cell In[2], line 21
19 # Wait for the announcement elements to be visible
20 wait = WebDriverWait(driver, 10) # Adjust the timeout value as needed
---> 21 announcement_elements = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.el-table-box[v-if$='!specialAnnounce']")))
22 print(driver.page_source)
23 # Extract the latest announcements within 2 hours
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py:95, in WebDriverWait.until(self, method, message)
93 if time.monotonic() > end_time:
94 break
---> 95 raise TimeoutException(message, screen, stacktrace)
TimeoutException: Message: