基于问题Scraping a specific website with a search box and javascripts in Python,我试图从网站https://www.msci.com/esg-ratings/中获取公司评级 ,主要是在搜索框,在下拉菜单中选择该名称的所有选项(“RIO TINTO LIMITED”和“RIO TINTO PLC”此处为“rio tinto”),并在两者的右上角获得带有评级的图片。
但是,我在处理建议公司的 ul-li 退出菜单时遇到了麻烦:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.add_argument('-headless')
options.add_argument('-no-sandbox')
options.add_argument('-disable-dev-shm-usage')
options.add_argument('window-size=1920,1080')
wd = webdriver.Chrome(options=options)
wd.get('https://www.msci.com/esg-ratings')
WebDriverWait(wd, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="_esgratingsprofile_keywords"]'))).send_keys("RIO TINTO")
WebDriverWait(wd, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ui-id-1"]/li[1]'))).click()
#WebDriverWait(wd,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#_esgratingsprofile_esg-ratings-profile-header > div.esg-ratings-profile-header-ratingdata > div.ratingdata-container > div.ratingdata-outercircle.esgratings-profile-header-yellow > div")))
print(wd.find_element_by_xpath('//*[@id="_esgratingsprofile_esg-ratings-profile-header"]/div[2]/div[1]/div[2]/div'))
(代码给出了 ElementClickInterceptedException。)
如何访问“RIO TINTO LIMITED”和“RIO TINTO PLC”所需的数据?
慕工程0101907
相关分类