split string problems
Larry Bates
larry.bates at websafe.com
Fri Sep 8 09:55:47 EDT 2006
Tempo wrote:
> Hey. I am trying to grab the prices from the string below but I get a
> few errors when I try to do it: Take a look at the code and error
> messages below for me and thanks you in advanced to all that help.
> Thank you. Here's the code & error messages:
>
>>>> p
> [<span class="sale">
> $14.99
> </span>, <span class="sale">
> $27.99
> </span>, <span class="sale">
> $66.99
> </span>, <span class="sale">
> $129.99
> </span>, <span class="sale">
> $254.99
> </span>]
>>>> p.split()[2]
>
> Traceback (most recent call last):
> File "<pyshell#11>", line 1, in -toplevel-
> p.split()[2]
> AttributeError: 'ResultSet' object has no attribute 'split'
>
The contents of p is rather "odd" looking. It isn't html that
was read from a website (note the commas after </span>). You
show it as if it is a list of strings, but the strings don't
have quotes around them. How are you creating the object p?
If you would just get it into a single string (with something
like:
x=urllib.urlopen(url)
p=x.read()
then you can use elementree, or beautiful soup to get your
prices quite easily.
-Larry
More information about the Python-list
mailing list