使用Python Selenium从弹出窗口中提取内容

问题描述 投票:0回答:1

我想从此网页提取一个人的简历(“约翰·赖恩斯伯格(John Reinsberg是Lazard资产管理公司的副主席,负责监督...”):

https://www.morningstar.com/funds/xnas/lziex/people

我的代码不起作用,因为内容在弹出窗口中。从一些现有的问题来看,似乎我需要使用click(),然后从窗口中查找元素。但是,我不知道如何找到要单击的元素。谢谢。

See the picture for example

我也尝试过,但是没有用:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(options=options)
driver.get('https://www.morningstar.com/funds/xnas/lziex/people')
element=driver.find_elements_by_xpath('//*[@class="sal-modal-biography ng-binding ng-scope"]')
print(element.text) 

这里是HTML的一部分。

element =  driver.find_element_by_xpath("//button[@class='sal-icons sal-icons--close mds-button mds-button--icon-only']")
driver.execute_script('arguments[0].click();',element)

driver.switch_to_alert()
print(driver.find_elements_by_xpath('//*[@class="sal-modal-biography ng-binding ng-scope"]'))

我想从以下网页中提取一个人的简历(“约翰·赖恩斯伯格(John Reinsberg是Lazard资产管理公司的副主席,负责监督...”):https://www.morningstar.com/funds/xnas/ lziex / ...

python selenium selenium-webdriver modal-dialog webdriverwait
1个回答
0
投票

要从网页<div class="sal-component-ctn sal-modal-scrollable" style="display: block;" aria-hidden="true"><div class="sal-component-mip-manager-pop-out reveal-modal mds-modal ng-isolate-scope open" data-reveal="" manager-data="vm.managerData" style="display: block; opacity: 1; visibility: visible; top: 335.333px;" tabindex="0" aria-hidden="false"> <div class="sal-row"> <div class="sal-manager-modal"> <div class="sal-manager-modal__modalHeader" ng-class="{'sal-fixed':vm.fixedHeader}" ng-style="vm.headerStyle" style="height: auto; width: auto;"> <span class="sal-modal-header__menu"> <button class="sal-icons sal-icons--close mds-button mds-button--icon-only" type="button"> <svg class="mds-icon mds-button__icon mds-button__icon--left"> <use xlink:href="#remove"> <title class="ng-binding">Close</title> </use> </svg> </button> </span> <div class="sal-modal-header__title ng-binding"> John R. Reinsberg </div> </div> <div class="sal-manager-modal__body" ng-style="{'margin-top': vm.headerStyle.height}" style="margin-top: auto;"> <div class="sal-modal-dps"> <ul class="sal-xsmall-block-grid-2 small-block-grid-3 medium-block-grid-5 large-block-grid-5"> </ul> </div> <!-- ngIf: vm.managerModalData.fundManager.biography.managerProvidedBiography || (vm.managerModalData.fundManager.CollegeEducationDetailList && vm.managerModalData.fundManager.CollegeEducationDetailList.length > 0) --><div class="sal-columns sal-small-12 sal-medium-6 sal-large-6 ng-scope" ng-if="vm.managerModalData.fundManager.biography.managerProvidedBiography || (vm.managerModalData.fundManager.CollegeEducationDetailList &amp;&amp; vm.managerModalData.fundManager.CollegeEducationDetailList.length > 0)" ng-class="{'sal-medium-12 sal-large-12': !vm.managerModalData.currentManagedFundList || vm.managerModalData.currentManagedFundList.length === 0}"> <!-- ngIf: vm.managerModalData.fundManager.biography.managerProvidedBiography --><div class="sal-modal-biography ng-binding ng-scope" ng-if="vm.managerModalData.fundManager.biography.managerProvidedBiography"> <!-- ngIf: !vm.managerModalData.fundManager.biography.isLocalized --> John Reinsberg is Deputy Chairman of Lazard Asset Management responsible for oversight of the firm's international and global strategies. He is also a Portfolio Manager/Analyst on the Global Equity and International Equity portfolio teams. He began working in the investment field in 1981. Prior to joining Lazard in 1992, John was Executive Vice President with General Electric Investment Corporation and Trustee of the General Electric Pension Trust. </div><!-- end ngIf: vm.managerModalData.fundManager.biography.managerProvidedBiography --> </div> </div> </div> </div> </div> </div></div> 中提取“ John Reinsberg是Lazard资产管理公司负责监督的副主席的简历...”,您需要为https://www.morningstar.com/funds/xnas/lziex/people引入WebDriverWait

© www.soinside.com 2019 - 2024. All rights reserved.