[英]Accessing table using splinter in Python
I am trying to write a small python script that scrape tracking details for an internal system. 我正在尝试编写一个小的python脚本,以抓取内部系统的跟踪详细信息。 The details are presented in a html table below.
详细信息显示在下面的html表中。 I am looking to turn it into python tuples:
我想把它变成python元组:
(processed, unit b door 3, 30-MAY-16 12:19) (created, unit b door 2, 30-MAY-16 06:17) (已处理,b单元3门,16年5月30日12:19)(已创建,b单元2门,16年5月30日6:17)
for example. 例如。 I am using Splinter.
我正在使用Splinter。
<table class="resultView" cellspacing="0" rules="all" border="1" style="width:540px;border-collapse:collapse;">
<tr class="clearHeader">
<th align="left" scope="col">Activity</th><th scope="col"> </th><th align="center" scope="col">Date</th>
</tr>
<tr class="statusRow">
<td style="width:30%;">Processed</td>
<td align="center"> Unit B<br /> Door 3 </td>
<td align="center" style="width:20%;">30-May-16<br/>12:19</td>
</tr>
<tr class="statusAlternate">
<td style="width:30%;">Created</td>
<td align="center"> Unit B <br /> Door 2</td>
<td align="center" style="width:20%;">30-May-16<br/>06:17</td>
</tr>
</table>
If I run: 如果我运行:
for update in browser.find_by_css('tr'):
print update.find_by_css('td')
it displays: 它显示:
[<splinter.driver.webdriver.WebDriverElement object at 0x103085e90>,
<splinter.driver.webdriver.WebDriverElement object at 0x103085ed0>,
<splinter.driver.webdriver.WebDriverElement object at 0x1030b4050>]
Which is what I would have expected. 这是我所期望的。 However, I cannot access the value from it.
但是,我无法从中访问该值。 Changing the line to:
将行更改为:
print update.find_by_css('td').value
gives the error: 给出错误:
AttributeError: 'ElementList' object has no attribute 'value'
This is a list so I try to access the first element on the list with 这是一个列表,因此我尝试使用以下命令访问列表中的第一个元素
print update.find_by_css('td').first.value
I then get this error: 然后我得到这个错误:
splinter.exceptions.ElementDoesNotExist: no elements could be found with css "td"
I cannot work out what I am doing wrong? 我无法弄清楚我做错了什么?
I think that your problem is that you are looking for "tr" or "td" into your table with css 'tr' or 'td' and any of the "tr" and/or "td" in your hable don't have this class 我认为您的问题是,您正在使用css'tr'或'td'在表中查找“ tr”或“ td”,而在寓言中没有任何“ tr”和/或“ td”这节课
I suggest you to this case, use xpath to look for elements that you want to find 我建议您在这种情况下,使用xpath查找要查找的元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.