我試圖在同一個類中查找使用屬性的元素,下面是該元素div class="outcome-pricedecimal " data-markettypecategory="00000000-0000-0000-da7a-000000580001" data-pd="1.66">1.66 </div>我想使用 data-pd="1.66" 來定位它,它是我需要的十進制數,因為如果小數點已更改為我的首選值,我希望它找到該元素(例如,當 =1.05 時查找 data-pd)我嘗試過使用此代碼找到它driver.find elements_by_xpath("//div[contains(number()driver.find_elements_by_css_selector('div.data-pd="1.05)"而不是:(.outcome-pricedecimal) (.data-markettypecategory="00000000-0000-0000-da7a-000000580001)"]')[0].click ()driver.find_element_by_css_selector(div.1.01)謝謝你的回答和幫助...
1 回答

鳳凰求蠱
TA貢獻1825條經驗 獲得超4個贊
就用BeautifulSoup這個吧。這是使用以下方法執行此操作的代碼BeautifulSoup:
from bs4 import BeautifulSoup
html = '<div class="outcome-pricedecimal " data-markettypecategory="00000000-0000-0000-da7a-000000580001" data-pd="1.66">1.66 </div>'
soup = BeautifulSoup(html,'html5lib')
div = soup.find('div')
data_pd = div['data-pd']
print(data_pd)
輸出:
1.66
如果你仍然想用 來做selenium,那么你可以這樣做:
data_pd = driver.find_element_by_class_name("outcome-pricedecimal ").get_attribute('data-pd')
print(data_pd)
添加回答
舉報
0/150
提交
取消