【发布时间】:2020-07-14 18:28:21
【问题描述】:
基于问题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 dropout 菜单时遇到了麻烦:
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”所需的数据?
【问题讨论】:
-
您是否使用无头,因为网站是从脚本动态生成的?
-
@RobertHarvey 我在 Google Colab 工作,如果没有 headless,webdriver 无法启动。
-
@gostinnaya 看到我的回答并询问是否有疑问
标签: javascript python selenium web-scraping selenium-chromedriver