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

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

Selenium 未通過(guò) XPath 查找元素(盡管在瀏覽器中可見(jiàn))

Selenium 未通過(guò) XPath 查找元素(盡管在瀏覽器中可見(jiàn))

蝴蝶刀刀 2023-09-18 17:24:06
所以我試圖獲取該網(wǎng)站的左側(cè)欄: https:?//experience.arcgis.com/experience/685d0ace521648f8a5beeeee1b9125cd以獲取當(dāng)前的世界衛(wèi)生組織冠狀病毒數(shù)據(jù)。我通過(guò) Xpath 定位國(guó)家/地區(qū),我的代碼是:from selenium import webdriverimport timedriver = webdriver.Firefox()driver.get("link_to_the_page")time.sleep(30)countries = country = "/html/body/div/div/div[2]/div/div/div/margin-container/full-container/div[10]/margin-container/full-container/div/div[2]/nav/span/div/div/p/span"countries_name = driver.find_elements_by_xpath(countries)但是當(dāng)我運(yùn)行這個(gè)時(shí),列表是空的,這很奇怪,因?yàn)楫?dāng) Firefox 使用 Selenium 顯示頁(yè)面時(shí),頁(yè)面看起來(lái)完全相同。那么為什么瀏覽器找不到元素呢?
查看完整描述

3 回答

?
偶然的你

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

或者,您可以直接在此處獲取數(shù)據(jù):

https://services.arcgis.com/5T5nSi527N4F7luB/arcgis/rest/services/Historic_adm0_v3/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=ADM0_NAME%2Ccum_conf%2CDateOfDataEntry&orderByFields=DateOfDataEntry%20asc&resultOffset=2000&resultRecordCount=2000&cacheHint=true

解析json,然后做你想做的事。

https://img1.sycdn.imooc.com//650817760001604711210227.jpg

查看完整回答
反對(duì) 回復(fù) 2023-09-18
?
翻過(guò)高山走不出你

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

由于所需的元素位于一個(gè)內(nèi)部,<iframe>因此要訪(fǎng)問(wèn)所需的元素,您必須:


誘導(dǎo)WebDriverWait等待所需的frame_to_be_available_and_switch_to_it().

誘導(dǎo)WebDriverWait等待所需的visibility_of_all_elements_located().

您可以使用以下定位策略:


driver.get("https://experience.arcgis.com/experience/685d0ace521648f8a5beeeee1b9125cd")

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME,"iframe")))

print([my_elem.text for my_elem in WebDriverWait(driver,20).until(EC.visibility_of_all_elements_located((By.XPATH, "//strong[contains(., 'areas or territories with cases')]//following::div[1]//div[@class='external-html']//span")))])

控制臺(tái)輸出:


['China :81151 cases', 'Italy :31506 cases', 'Iran (Islamic Republic of) :16169 cases', 'Spain :11178 cases', 'Republic of Korea :8413 cases', 'France :7652 cases', 'Germany :7156 cases', 'United States of America :4356 cases', 'Switzerland :2650 cases', 'The United Kingdom :1954 cases', 'Netherlands :1705 cases', 'Belgium :1486 cases', 'Austria :1471 cases', 'Norway :1423 cases', 'Sweden :1167 cases', 'Denmark :1044 cases', 'Canada :993 cases', 'Japan :873 cases', 'International conveyance (Diamond Princess) :712 cases', 'Malaysia :673 cases', 'Australia :510 cases', 'Czechia :464 cases', 'Portugal :448 cases', 'Qatar :442 cases', 'Greece :387 cases', 'Finland :319 cases', 'Israel :304 cases', 'Ireland :292 cases', 'Slovenia :275 cases', 'Singapore :266 cases', 'Estonia :258 cases', 'Poland :246 cases', 'Romania :246 cases', 'Pakistan :241 cases', 'Bahrain :237 cases', 'Brazil :234 cases', 'Iceland :225 cases', 'Thailand :212 cases', 'Luxembourg :203 cases', 'Chile :201 cases', 'Egypt :196 cases', 'Philippines :187 cases', 'Indonesia :172 cases', 'Saudi Arabia :171 cases', 'Iraq :154 cases', 'India :147 cases', 'Kuwait :142 cases', 'Lebanon :120 cases', 'Peru :117 cases', 'Russian Federation :114 cases', 'United Arab Emirates :113 cases', 'San Marino :104 cases', 'Turkey :98 cases', 'Slovakia :97 cases', 'Mexico :93 cases', 'Panama :86 cases', 'Serbia :85 cases', 'South Africa :85 cases', 'Bulgaria :81 cases', 'Argentina :79 cases', 'Latvia :71 cases', 'Viet Nam :66 cases', 'Colombia :65 cases', 'Croatia :65 cases', 'Algeria :60 cases', 'Ecuador :58 cases', 'Hungary :58 cases', 'Brunei Darussalam :56 cases', 'Albania :55 cases', 'Armenia :52 cases', 'Costa Rica :50 cases', 'Morocco :49 cases', 'Jordan :48 cases', 'Faroe Islands :47 cases', 'Belarus :46 cases', 'occupied Palestinian territory :44 cases', 'Sri Lanka :42 cases', 'Georgia :38 cases', 'Malta :38 cases', 'Venezuela (Bolivarian Republic of) :36 cases', 'Azerbaijan :34 cases', 'Cambodia :33 cases', 'Cyprus :33 cases', 'Kazakhstan :33 cases', 'Oman :33 cases', 'North Macedonia :31 cases', 'Senegal :31 cases', 'Republic of Moldova :30 cases', 'Uruguay :29 cases', 'Guadeloupe :27 cases', 'Bosnia and Herzegovina :26 cases', 'Lithuania :26 cases', 'Tunisia :24 cases', 'Afghanistan :22 cases', 'Dominican Republic :21 cases', 'Burkina Faso :20 cases', 'New Zealand :20 cases', 'Andorra :16 cases', 'Martinique :16 cases', 'Uzbekistan :16 cases', 'Ukraine :14 cases', 'Maldives :13 cases', 'Bolivia (Plurinational State of) :12 cases', 'Jamaica :12 cases', 'Réunion :12 cases', 'French Guiana :11 cases', 'Paraguay :11 cases', 'Bangladesh :10 cases', 'Cameroon :10 cases', 'Monaco :9 cases', 'Honduras :8 cases', 'Rwanda :8 cases', 'Democratic Republic of the Congo :7 cases', 'Ghana :7 cases', 'Liechtenstein :7 cases', 'Ethiopia :6 cases', 'Guatemala :6 cases', 'C?te d’Ivoire :6 cases', 'Cuba :5 cases', 'Jersey :5 cases', 'Mongolia :5 cases', 'Trinidad and Tobago :5 cases', 'Guam :5 cases', 'Guyana :4 cases', 'Kenya :4 cases', 'Seychelles :4 cases', 'Aruba :4 cases', 'Curacao :3 cases', 'Equatorial Guinea :3 cases', 'French Polynesia :3 cases', 'Gabon :3 cases', 'Gibraltar :3 cases', 'Mayotte :3 cases', 'Nigeria :3 cases', 'Puerto Rico :3 cases', 'Saint Barthelemy :3 cases', 'Namibia :2 cases', 'Saint Martin :2 cases', 'Saint Lucia :2 cases', 'United States Virgin Islands :2 cases', 'Liberia :2 cases', 'Montenegro :2 cases', 'Barbados :2 cases', 'Antigua and Barbuda :1 cases', 'Bhutan :1 cases', 'Cayman Islands :1 cases', 'Central African Republic :1 cases', 'Congo :1 cases', 'Eswatini :1 cases', 'Guernsey :1 cases', 'Guinea :1 cases', 'Holy See :1 cases', 'Mauritania :1 cases', 'Nepal :1 cases', 'Saint Vincent and the Grenadines :1 cases', 'Sudan :1 cases', 'Togo :1 cases', 'Suriname :1 cases', 'Somalia :1 cases', 'Benin :1 cases', 'United Republic of Tanzania :1 cases', 'Bahamas :1 cases', 'Gambia :1 cases', 'Djibouti :1 cases', 'Montserrat :1 cases']

注意:您必須添加以下導(dǎo)入:


from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC


查看完整回答
反對(duì) 回復(fù) 2023-09-18
?
阿晨1998

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

先進(jìn)入iframedriver.switch_to.frame(driver.find_element_by_css_selector("/html/body/div[2]/div[1]/div/div/div/div/div/div/div/iframe"))


country = driver.find_element_by_xpath("//*[@id="Cases_by_country_pt_V3_6708_0_layer"]/circle[32]")

country .click()

不要復(fù)制“完整xpath”,應(yīng)該復(fù)制“xpath”


查看完整回答
反對(duì) 回復(fù) 2023-09-18
  • 3 回答
  • 0 關(guān)注
  • 240 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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