I am trying to write a small python script that scrape tracking details for an internal system. The details are presented in a html table below. I am looking to turn it into python tuples:
(processed, unit b door 3, 30-MAY-16 12:19) (created, unit b door 2, 30-MAY-16 06:17)
for example. I am using 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
I suggest you to this case, use xpath to look for elements that you want to find
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.