我在 Python 項目中使用 Selenium,我想使用以下代碼獲取表中的數(shù)據(jù):xpath = "//div[@id='tab_highscore']//table[contains(@class, 'highscore')]//tr"users = driver.find_elements_by_xpath(xpath)for u in users: xpath = "//td[@class='name']" userTd = u.find_elements_by_xpath(xpath)[0] user = userTd.get_attribute('innerText') xpath = "//td[@class='score']" scoreTd = u.find_elements_by_xpath(xpath)[0] score = scoreTd.get_attribute('innerText') usersArr.append({"name":user, "ally":ally, "score":score})在用戶和分?jǐn)?shù)中我總是得到第一個 tr 值的問題,知道問題是什么嗎?
Python Selenium使用xpath從tr內(nèi)的td獲取數(shù)據(jù)
叮當(dāng)貓咪
2023-09-26 14:35:16