BeautifulSoup, 'ResultSet' object has no attribute 'find_all' - python-2.7

I read other threads related to my issue but it did not solve the problem.
<h2 class="tabellen_ueberschrift al">Cards</h2>
<div class="fl" style="width:49%;">
<table class="tabelle_grafik lh" cellpadding="2" cellspacing="1">
<tr>
<th class="al" colspan="3">CA Osasuna</th>
</tr>
<td class="s10 al">
Sisi
<br />
26. min. 2. yellow card, Time wasting </td>
</tr>
I want to get all the a tags (there will be several) within the table so my code is this:
header = soup.find('h2', text="Cards")
cards_table = header.find_next_siblings(limit=2)
for row in cards_table.find_all('a'):
print row
This raises me
AttributeError: 'ResultSet' object has no attribute 'find_all'
cards_table is a table and I iterate over it with the for loop so not sure why this is causing the error. Ideas please?

Ok, the code was missing one line:
for line in cards_table:
for row in line.find_all('a'):
print row
cards_table is a list so we had to iterate over it before we could use the find_all method for the table.

Related

Trouble converting number from query result to float in the template

i have an sql stored procedure returning me values (Characteristics and their value).
The values are real in the table, fixed to 2 decimals, the table doesn't seem to be the problem since the numbers are stored properly.
The problem come when i load my template (i use Python+Django), those value are listed in a tab :
<table id="regnorme3Tab" name="regnorme3Tab" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>Code</th>
<th style="width:200px">Libellé</th>
<th>Limite inf</th>
<th>Valeur</th>
<th>limite sup</th>
</tr>
</thead>
<tbody>
{% for reg_norme in reg_savs %}
{%if reg_norme.Saisie == 'O' %}
<tr name="Reg_Normes" id="{{reg_norme.regauxnormes}}">
<th><span> {{reg_norme.Id}}</span></th>
<th class="codevalue"><span> {{reg_norme.Code}}</span></th>
<th style="width:200px"><span> {{reg_norme.LibEtendu}}</span></th>
<th><span> {{reg_norme.LimitInf}}</span></th>
<th><span><input type="number" max="{{reg_norme.LimitSup}}" step="0.01" min="{{reg_norme.LimitInf}}"class="{{reg_norme.Code}}" id="{{reg_norme.Id}}" value="{{reg_norme.Valeur}}" required style="width:40px;"></span></th>
<th><span> {{reg_norme.LimitSup}}</span></th>
</tr>
{%endif%}
{% endfor %}
</tbody>
</table>
If i leave things like that, nothing is displayed in my input, i had the same problem on some isolated number input and i managed to display the data by using parseFloat() and toFixed(2).
document.getElementById('ebHumValue').value = parseFloat({{displayHUMHumidite}}).toFixed(2);
So i though i would create a function with a loop on my tab and use parseFloat and toFixed to display something.
$("#regnorme3Tab :input").each(function () {
var number = this.name;
this.value = number;
alert(parseFloat(this.name).toFixed(2));
});
The function is in document.ready so it would format the number correctly after loading.
But the problem is that i doesn't work in the tab, i tried to display the value at different stage, for reason i don't understand first it change from like 22.4 (in the table) to 22.3999945754 when i print it, when i use parseFloat() on it, it become 22 and even if i use toFixed(2) with it, it become 22.00 and i don't really get why since the same conversion on isolated input work on my page.
Any idea why the base value get changed like that in the first place ? And how i can manage to cast that so it would display the correct number ?
Hi have you tried to use the template gabarit floatformat builtin ?
{{ displayHUMHumidite |floatformat:2 }}
source here : https://docs.djangoproject.com/fr/2.0/ref/templates/builtins/#floatformat

Display ColdFusion Query Output in a Formatted Table

Let me begin by saying that I'm a novice at ColdFusion and trying to learn so please bear with me.
I work in an apartment complex that caters to students from the local college. We have one, two and four bedroom apartments. Each room in an apartment is leased to an individual student. What I want to do is populate an HTML table with all the people in a room. My query is working and pulling all the relevant data but what is happening is that each person is being split out to their own HTML table instead of all the people in a room being put into the same table. Here is an example:
What I want
What is happening:
Here is my code:
<!---Begin data table--->
<cfoutput query = "qryGetAssignments">
<div class="datagrid">
<table>
<tr><td align="right"><strong>#RoomType#</strong></td></tr>
<thead>
<tr>
<th>#RoomNumber#</th>
</thead>
<tbody>
<tr><td><strong>#Bed#</strong>
| #FirstName# #LastName# :: #StudentNumber#
</td>
</tr>
</tbody>
</table>
</div>
</cfoutput>
I know why the output is coming out like it is, I just don't know how to fix it. I want there to be four residents in one table for a four bedroom apartment, two residents in a table for a two bedroom, and so on. Thanks in advance for your help.
Edit:
Sorry about the confusion. Here is a full pic of what I'm going for:
This should do what you need, assuming your query is properly ordered by roomType, for the <cfoutput group=""> to work.
<!---Begin data table--->
<cfoutput query="qryGetAssignments" group="roomType">
<div class="datagrid"><!--- If this isn't needed to style the tables, it can be moved outside the loop --->
<table>
<tr><td align="right"><strong>#qryGetAssignments.roomType#</strong></td></tr>
<thead>
<tr>
<th>#qryGetAssignments.roomNumber#</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>#qryGetAssignments.bed#</strong>
<cfoutput><!--- this output here will loop over rows for that groupby --->
| #FirstName# #LastName# :: #StudentNumber#
</cfoutput>
</td>
</tr>
</tbody>
</table>
</div>
</cfoutput>
I've also scoped your query variables, at least I believe they are variables from a query.
That should work except it might need to be grouped by "roomNumber" such as N108.

How to handle dynamically changing id's with similar starting name using Webdriver

I am automating the test for web application. I have a scenario for creating an admin, for which i have to enter the name, email address and phone number text boxes. But ids of this text boxes are dynamic.
userName, id='oe-field-input-41'
Email, id='oe-field-input-42'
phone number, id='oe-field-input-43'
First Query:
The numbers in the ids are dynamic, it keep changes
I tired to use the xpath for handling the dynamic value.
xpath = //*[starts-with(#id,'oe-field-input-')]
In this it enter the text into first text box successfully
Second Query:
I am not able use the same xpath for next two text boxes, as it enters the email and phone number into name field only
Please help me to resolve this dynamic value handling.
Edited: added the html code,
<table class="oe_form_group " cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr class="oe_form_group_row">
<td class="oe_form_group_cell oe_form_group_cell_label" width="1%" colspan="1">
<td class="oe_form_group_cell" width="99%" colspan="1">
<span class="oe_form_field oe_form_field_many2one oe_form_field_with_button">
<a class="oe_m2o_cm_button oe_e" tabindex="-1" href="#" draggable="false" style="display: inline;">/</a>
<div>
</span>
</td>
</tr>
<tr class="oe_form_group_row">
<td class="oe_form_group_cell oe_form_group_cell_label" width="1%" colspan="1">
<td class="oe_form_group_cell" width="99%" colspan="1">
<span class="oe_form_field oe_form_field_email">
<div>
<input id="oe-field-input-35" type="text" maxlength="240">
</div>
</span>
</td>
</tr>
<tr class="oe_form_group_row">
<td class="oe_form_group_cell oe_form_group_cell_label" width="1%" colspan="1">
<td class="oe_form_group_cell" width="99%" colspan="1">
<span class="oe_form_field oe_form_field_char">
<input id="oe-field-input-36" type="text" maxlength="32">
</span>
</td>
</tr>
<tr class="oe_form_group_row">
<td class="oe_form_group_cell oe_form_group_cell_label" width="1%" colspan="1">
<td class="oe_form_group_cell" width="99%" colspan="1">
<span class="oe_form_field oe_form_field_char">
<input id="oe-field-input-37" type="text" maxlength="32">
</span>
</td>
</tr>
<tr class="oe_form_group_row">
</tbody>
you can try alternate way for locating unique element by label or so. For example:
css=.oe_form_group_row:contains(case_sensitive_text) input
xpath=//tr[#class = 'oe_form_group_row'][contains(.,'case_sensitive_text')]//input
If you are using ISFW you should create custom component for such form fields.
You do have some classes which are good for identification, e.g. oe_form_field_email, oe_form_field_char. It's a little complicated to use them because they're not on the input fields themselves, and the second one is not unique; but it's quite possible:
.//span[contains(#class, 'oe_form_field_email')]//input
That is an xpath which identifies the Email field as being the input which is a descendant of a span with the oe_form_field_email class. You could also use the same logic in a css selector like this, more efficiently:
span.oe_form_field_email input
For the two other fields, there is no unique class which can tell them apart so you're going to have to rely on the order (I'm assuming username comes before phone number), and that means you have to use xpaths:
(//tr//span[contains(#class, 'oe_form_field_char')])[1]//input
(//tr//span[contains(#class, 'oe_form_field_char')])[2]//input
Those xpaths pick out the first and second fields respectively, which are inputs which are descendants of a span of class oe_form_field_char.
P.S. I used Firepath in firefox to verify the xpath and css locators.
The problem here is, that your XPath does the correct selection, but Selenium will always pick the first one if multiple results are returned for your query.
You can select each of the input fields directly by using:
//input[1]
//input[2]
//input[3]
If there are other input fields, you can tighten your selection by selecting only input nodes with oe-field-input in their id attribute like this:
//input[starts-with(#id,'oe-field-input-')][1]
//input[starts-with(#id,'oe-field-input-')][2]
//input[starts-with(#id,'oe-field-input-')][3]
Use the following xpath works like a charm. Although I don't recommend this kind of an xpath. Since we don't have text against the text box no other choice.
//div/input[contains(#id, 'oe-field-input')] - First text box
//tr[#class = 'oe_form_group_row'][2]//input - Second text box
//tr[#class = 'oe_form_group_row'][3]//input - Third text box
You can use below XPATH.
//tr[#class = 'oe_form_group_row'][2]//input for First Text box
//tr[#class = 'oe_form_group_row'][3]//input for Second Text box
//tr[#class = 'oe_form_group_row'][4]//input for Third text box.
I have tested avove xpath.
But the better way if you have development access then ask developers to make is standaralized and recommand tags like "name" , "value", or attach text e.g. Email:, Password. So you can use these in your xpath.

emberjs - nested tables info

I have an irregular table structure I would like to nest (either using actual tables or using div tables). I have a list of 'Parent' classes, each of which has many 'Children' instances, and I want to show them in the same table, with a single set of headers. I would like the output to be something like this (simplified - I have many more columns to display).
<table>
<tr>
<th>Parent</th>
<th>Child</th>
<th>Remove</th>
</tr>
<tr>
<td colspan="2">parent one</td>
<td>child one</td>
</tr>
<tr>
<td>child two</td>
</tr>
</table>
But I can't figure out how to accomplish this in handlebars because of the fact that I need to have a new <tr> element around every child except for the first one. This is easy enough to figure out in code, but I can't see how to do it cleanly in handlebars. Is it possible or should I write a custom view?

django and dataTables - speed up query and page display

I have a page in my app that lists all our client records - about a thousand total. The query is straight forward (two queries, actually) and look like this (one for commercial and one for residential):
all_comm = System.objects.all().filter(isRessy=False)
all_ressy = System.objects.all().filter(isRessy=True)
In my template, I simply iterate over both queries displaying the information in a table. This code looks like this:
<table style="width:100%;" class="field_container dt full-border">
<thead>
<tr>
<th align=left width=200>Owner</th>
<th align=center width=100>System ID</th>
<th align=left>System Address</th>
<th align=center width=200>Options</th>
</tr>
</thead>
<tbody>
{% for System in all_ressy %}
<tr onclick="window.location.href='{% url cpm.systems.views.system_overview System.systemID %}'">
<td>{{ System.billingContact.lastName }}, {{ System.billingContact.firstName }}</td>
<td align=center>{{ System.pk }}</td>
<td>{{ System.systemAddress }}, {{ System.systemCity }}</td>
<td align=center>
Create Service Call
</td>
</tr>
{% endfor %}
</tbody>
</table>
This code is identical for showing all the commercial records. If you'll notice that I have a class of dt listed in the table. That sets the table to be a dataTable table. As such, the rows get nice highlighting, the columns can be sorted, and there's a search box at the top of the table. All nice stuff.
The problem is that the page, as a whole, is a bit slow to load. It seems that half of the loading time is the raw displaying of data (fetching data then iterating over all the records generating the basic HTML table). The second half of the loading time (or at least a decent chunk of the time) looks to be devoted to converting the regular table into a dataTable.
I'm wondering if there's anything I can do to speed this whole process up. I've tried using pagination on the dataTable but that seems to be useless since all the records are loaded anyway, just hidden across multiple dataTable pages. Real pagination for the whole page isn't really possible given the nature of the app. I feel like the queries aren't going to get any faster so there's got to be optimization or some trick to make this page load faster.
Any thoughts?
Thanks for the help
Edit I'm referring to this dataTable plugin: http://datatables.net/index
You could try using ajax to load the data directly into the DataTable It would remove the HTML rendering step.
http://datatables.net/release-datatables/examples/ajax/objects.html (I assume this is the datatables you are talking about...)