[Tutor] Modifying files in a directory.

qsqgeekyogdty at tiscali.co.uk qsqgeekyogdty at tiscali.co.uk
Fri May 30 10:28:27 CEST 2008


Hello,
Thanks for the replies, I have now installed ipython and will take the 
time to explore each object further.

But I have one more question.

On each page I have several 

<td class="order_tbl_price"><span
class="order_table_price_small">From</span> $32.66</td>

each with different price.

so, changing the code to use the findAll, returns a list:

>>> otp = soup.findAll('td', {'class': 'order_tbl_price'})
>>> otp
[<td class="order_tbl_price"><span class="order_table_price_small"
>From</span> $32.66</td>, <td class="order_tbl_price">$79.99</td>, <td 
class="order_tbl_price">$39.99</td>, <td class="order_tbl_price"><span 
class="order_table_price"><span class="order_table_price_small">1 Full 
Pack  - </span> $65.95
                </span></td>]
>>>
>>>
>>> price = float(otp.contents[1].lstrip(' $'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ResultSet' object has no attribute 'contents'
>>> 

Even if I do a limit=1 as

>>> otp = soup.findAll('td', {'class': 'order_tbl_price'}, limit=1)
>>> otp
[<td class="order_tbl_price"><span class="order_table_price_small"
>From</span> $32.66</td>]
>>> price = float(otp.contents[1].lstrip(' $'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ResultSet' object has no attribute 'contents'

then, i thought I would loop through this list:

>>> for x in otp:
...     print x
... 
<td class="order_tbl_price"><span class="order_table_price_small"
>From</span>$23.60</td>
<td class="order_tbl_price">$79.99</td>
<td class="order_tbl_price">$39.99</td>
<td class="order_tbl_price"><span class="order_table_price"><span 
class="order_table_price_small">1 Blister Pack  - </span> $65.95
                </span></td>
>>>

And here I get stuck as to how to modify all the prices?

Thanks in advance for any suggestions.

David







________________________
Guard against online ID theft - http://www.tiscali.co.uk/spyguard



More information about the Tutor mailing list