查找表selenium时未找到元素



我正试图读取表并获得地址和值列的值。返回找不到元素错误。页面:https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances

代码我代码:

driver=webdriver.Firefox()
ga=pandas.read_csv("contracts/adresses.csv")
for i in range (ga.size-1):
fj=ga.iloc[i][0]
# driver.get("https://etherscan.io/address/"+str(fj))
driver.get("https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances")
wait = WebDriverWait(driver,10)
frame = wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"tokeholdersiframe")))
print("udj")


simpleTable = driver.find_element(By.XPATH,"/html/body/div[2]/div[3]/table")


rows = simpleTable.find_elementsBy.TAG_NAME("tr")

for i in range(1,len(rows)):
cols = i.find_elements(By.TAG_NAME("td"))
for g in cols:
g.getText()

HTML代码:

<thead class="thead-light">
<tr>
<th scope="col" width="1">Rank</th>
<th scope="col">Address</th>
<th scope="col">Quantity
</th>
<th scope="col">Percentage</th>
<th id="col_value_Title" scope="col">Value</th>
<th id="col_analytics_Title" scope="col">Analytics</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td><span data-toggle="tooltip" title="" data-original-title="Public Tag: Binance 7
(0xbe0eb53f46cd790cd13851d5eff43d12404d33e8)"><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xbe0eb53f46cd790cd13851d5eff43d12404d33e8" target="_parent">Binance 7</a></span></td><td>8,623,839.536582375549486936</td><td>52.0150% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:100.0000%;" aria-valuenow="52.0150" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$3,659,513,869.72</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xbe0eb53f46cd790cd13851d5eff43d12404d33e8#tokenAnalytics" target="_parent"><i class="ml-2 fas fa-chart-line fa-lg"></i></a></td></tr><tr><td>2</td><td><span data-toggle="tooltip" title="" data-original-title="Public Tag: Binance 8
(0xf977814e90da44bfa03b6295a0616a897441acec)"><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xf977814e90da44bfa03b6295a0616a897441acec" target="_parent">Binance 8</a></span></td><td>4,500,000</td><td>27.1419% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:52.1809%;" aria-valuenow="27.1419" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$1,909,568,509.93</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xf977814e90da44bfa03b6295a0616a897441acec#tokenAnalytics" target="_parent"><i class="ml-2 fas fa-chart-line fa-lg"></i></a></td></tr><tr><td>3</td><td><span data-toggle="tooltip" title="" data-original-title="Public Tag: Binance 9
(0x001866ae5b3de6caa5a51543fd9fb64f524f5478)"><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0x001866ae5b3de6caa5a51543fd9fb64f524f5478" target="_parent">Binance 9</a></span></td><td>588,959.49910460999996837</td><td>3.5523% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:6.8294%;" aria-valuenow="3.5523" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$249,924,114.03</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0x001866ae5b3de6caa5a51543fd9fb64f524f5478#tokenAnalytics" target="_parent"><i class="ml-2 fas fa-chart-line fa-lg"></i></a></td></tr><tr><td>4</td><td><span><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xb4b3351918a9bedc7d386c6a685c42e69920b34d" target="_parent">0xb4b3351918a9bedc7d386c6a685c42e69920b34d</a></span></td><td>211,336.9</td><td>1.2747% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:2.4506%;" aria-valuenow="1.2747" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$89,680,508.72</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xb4b3351918a9bedc7d386c6a685c42e69920b34d#

代码中有很多语法错误:

rows = simpleTable.find_elementsBy.TAG_NAME("tr")

应该

rows = simpleTable.find_elements(By.TAG_NAME,"tr")

cols = i.find_elements(By.TAG_NAME("td"))

应该

cols = rows[i].find_elements(By.TAG_NAME,"td")

在python中使用.text.get_attribute("innerText")从WebElement中获得Text应该是这样的:

print(g.text)

试试下面的代码:

simpleTable = driver.find_element(By.XPATH, "//div[@id='maintable']//table")
rows = simpleTable.find_elements(By.TAG_NAME,"tr")
for i in range(1,len(rows)):
cols = rows[i].find_elements(By.TAG_NAME,"td")
for g in cols:
print(g.text)

!pip install selenium (jupyter notebook)

pip install selenium ( command prompt)

安装后再试!

相关内容

  • 没有找到相关文章

最新更新