在Selenium Web驱动程序(Python)中选择特定的表格单元格 [英] Selecting specific table cells in Selenium web driver (Python)

查看:322
本文介绍了在Selenium Web驱动程序(Python)中选择特定的表格单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从结构如下的页面链接中提取信息:

I am trying to extract the information from a link from a page that is structured as such:

...

<td align="left" bgcolor="#FFFFFF">$725,000</td>

<td align="left" bgcolor="#FFFFFF"> Available</td>

*<td align="left" bgcolor="#FFFFFF">
    <a href="/washington">


 Washington Street Studios
<br>1410 Washington Street SW<br>Albany, Oregon, 97321
</a>
</td>*

<td align="center" bgcolor="#FFFFFF">15</td>

<td align="center" bgcolor="#FFFFFF">8.49%</td>

<td align="center" bgcolor="#FFFFFF">$48,333</td>

</tr>

我尝试定位属性为'align = left'的元素并对其进行迭代,但这没有解决.如果有人可以帮助我用硒找到元素<a href = "/washington">(同一页面中的多个标签),我将不胜感激.

I tried targeting elements with attribute 'align = left' and iterating over it but that didn't work out. If anybody could help me locate the element <a href = "/washington"> (multiple tags like these within the same page) with selenium I would appreciate it.

推荐答案

根据我们目前提供的内容,有一个table,并且您在特定列中具有所需的链接.没有要依赖的面向数据"属性,但是使用列索引定位链接看起来足够好:

From what we have provided at the moment, there is a table and you have the desired links in a specific column. There are no "data-oriented" attributes to rely on, but using column index to locate the links looks good enough:

for row in driver.find_elements_by_css_selector("table#myid tr"):
    cells = row.find_elements_by_tag_name("td")

    print(cells[2].text)  # put a correct index here

这篇关于在Selenium Web驱动程序(Python)中选择特定的表格单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆