第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 Python 中使用 ul-li 下拉列表抓取網(wǎng)站?

如何在 Python 中使用 ul-li 下拉列表抓取網(wǎng)站?

森林海 2023-03-08 16:02:55
基于問(wèn)題Scraping a specific website with a search box and javascripts in Python,我試圖從網(wǎng)站https://www.msci.com/esg-ratings/中獲取公司評(píng)級(jí) ,主要是在搜索框,在下拉菜單中選擇該名稱的所有選項(xiàng)(“RIO TINTO LIMITED”和“RIO TINTO PLC”此處為“rio tinto”),并在兩者的右上角獲得帶有評(píng)級(jí)的圖片。但是,我在處理建議公司的 ul-li 退出菜單時(shí)遇到了麻煩:from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byoptions = 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。)如何訪問(wèn)“RIO TINTO LIMITED”和“RIO TINTO PLC”所需的數(shù)據(jù)?
查看完整描述

1 回答

?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊

我在處理推薦公司的 ul-li 退出菜單時(shí)遇到了麻煩


這是預(yù)期的,因?yàn)閑lement您的目標(biāo)是通過(guò)dynamic腳本呈現(xiàn)的。options.add_argument('-headless')為了克服這一點(diǎn),你將不得不避免。


你這里也有問(wèn)題


print(wd.find_element_by_xpath('//*[@id="_esgratingsprofile_esg-ratings-profile-header"]/div[2]/div[1]/div[2]/div'))

您嘗試打印元素的位置。由于目標(biāo)元素是icon由呈現(xiàn)的CSS,因此您不能使用print()來(lái)輸出它。相反,您需要將其保存為一個(gè).png文件


with open('filename.png', 'wb') as file:

    file.write(driver.find_element_by_xpath('//*[@id="_esgratingsprofile_esg-ratings-profile-header"]/div[2]/div[1]/div[2]/div').screenshot_as_png)

然后根據(jù)您的需要使用它。


查看完整回答
反對(duì) 回復(fù) 2023-03-08
  • 1 回答
  • 0 關(guān)注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)