【发布时间】:2019-01-28 05:52:14
【问题描述】:
我正在尝试解析 HTML 表格并单独单击第三列中的每个超链接(其中显示 href="javascript:showPayCheck)。有大量帖子显示如何解析表格,但我不能找不到任何看起来像我正在使用的表格:
<div class="screen-group-content">
<div class="checkview-checks">
<table cellpadding="2px" class="asureTable" cellspacing="0px" style="border-collapse: collapse;">
<tbody><tr class="trHeader">
<td style="font-weight: bold;">Payment Date</td>
<td style="font-weight: bold;">Payment Type</td>
<td style="font-weight: bold;">Check/ACH</td>
<td style="font-weight: bold;">View $</td>
</tr>
<tr>
<td style="cursor: default;">01/18/2019</td>
<td style="cursor: default;">Regular Check</td>
<td style="cursor: default;">ACH</td>
<td style="cursor: default;"><a href="javascript:showPayCheck(589, 3106, 'REG', 'D');" title="View Check Detail">$3,023.10</a></td>
</tr>
<tr>
<td style="cursor: default;">01/04/2019</td>
<td style="cursor: default;">Regular Check</td>
<td style="cursor: default;">ACH</td>
<td style="cursor: default;"><a href="javascript:showPayCheck(588, 3106, 'REG', 'D');" title="View Check Detail">$3,141.80</a></td>
</tr>
</tbody></table>
</div>
</div>
我尝试过使用 BeautifulSoup:
import BeautifulSoup as bSoup
soup = bSoup(driver.page_source, "html.parser")
td_list = soup.findAll('td')
for td in td_list:
print(td.text)
我已经尝试过 Selenium:
elems = driver.find_elements_by_name("td")
for elem in elems:
print(elem.text)
elem.click()
我什么都得不到。表的 XPath 是:
//*[@id="form1"]/div[3]/div/div/table
我已经尝试通过 XPath 获取表格:
table=driver.find_element_by_xpath('//*[@id="form1"]/div[3]/div/div/table')
for elem in table:
print(elem.text)
但我得到了错误:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="form1"]/div[3]/div/div/table"}
我做错了什么?
【问题讨论】:
-
能否提供网址??
-
检查表格是否在 frame/iframe 元素内
-
URL 在登录后面。让我刮掉整个页面。
标签: python selenium html-table beautifulsoup