簡體   English   中英

需要幫助使用帶日期輸入的 Selenium python 從網站提取表格

[英]Need help extracting tables from website using Selenium python with date input

這是我第一次使用 Selenium,我正在嘗試使用日期從https://www.fpi.nsdl.co.in/web/Reports/Archive.aspx中提取表格。 我可以在 chrome 驅動程序中打開日歷,但無法 select 所需的日期。 下面是我的代碼,有沒有辦法達到 select 月/年? 提前致謝

test_url = "https://www.fpi.nsdl.co.in/web/Reports/Archive.aspx"
driver = webdriver.Chrome(r"C:\Users\prash\Music\fii\chromedriver.exe")
driver.get(test_url)
time.sleep(1)
expected_to_date = '17'
driver.find_element_by_id("imgtxtDate").click()
from_day = driver.find_element_by_xpath("//td[not(contains(@class,'DynarchCalendar-firstcol'))]/a[text()='" + expected_to_date + "']")
from_day.click()
time.sleep(10)

您可以通過 XPath 定位屬性為dyc-date的div,與本站提供的日歷進行交互。 它的值似乎對應於一個日期。

這查看了 2022 年 5 月 10 日的報告:

from selenium import webdriver
import time
from selenium.webdriver.common.by import By

test_url = "https://www.fpi.nsdl.co.in/web/Reports/Archive.aspx"
driver = webdriver.Chrome()
driver.get(test_url)
time.sleep(1)
driver.find_element_by_id("imgtxtDate").click()
time.sleep(1)

#Go back a previous month
driver.find_element(By.CLASS_NAME, 'DynarchCalendar-prevMonth').click()
time.sleep(1)

#Click on the 5th day
driver.find_element(By.XPATH, "//div[@dyc-date='20220510']").click()
time.sleep(1)

#Submit
driver.find_element(By.ID, 'btnSubmit1').click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM