我想得到Holdings的字典。单击"持股"选项卡后,需要查找持股百分比。(https://www.moneycontrol.com/india/stockpricequote/auto-ancillaries/mothersonsumisystems/MSS01)
import os
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--start-maximized')
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(options=options)
company = "motherson sumi"
wait = WebDriverWait(driver, 20)
driver.get("https://www.moneycontrol.com")
inputElement = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#form_topsearch>.txtsrchbox.FL')))
inputElement.send_keys(company, Keys.ENTER)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#proceed-button'))).click()
driver.implicitly_wait(30)
driver.find_element_by_link_text("Shareholding").click()
driver.implicitly_wait(10)
div = driver.find_element_by_class_name('seemore')
z = div.find_element_by_css_selector('a').get_attribute('href')
print(z)
driver.get(z)
但是,我无法点击";参见Top Holdings";并在同一选项卡中打开链接。在那之后,我想在dict中获得最高持股。
这是一个Java脚本,希望能有所帮助。我没有测试。
driver.execute_script("driver.get_element_by_xpath("//*[@id="sharepattern"]/div[2]/div[1]/div[3]/a")