split string problems

T

Tempo

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:
[<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
said:

Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
p.split()[2]
AttributeError: 'ResultSet' object has no attribute 'split'
 
J

John McMonagle

[<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>]

Worked alright for me (see below). Are you sure "p" is a string ?

Cut and paste from interactive python shell:
.... [<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', 'class="sale">', '$14.99', '</span>,', '<span',
'class="sale">', '$27.99', '</span>,', '<span', 'class="sale">',
'$66.99' said:

Regards,

John
 
A

Andy Terrel

try str(p).split()[2]

your class is using the __str__ attribute to print and I am guessing
that is what you are seeing.
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:
[<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
said:

Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
p.split()[2]
AttributeError: 'ResultSet' object has no attribute 'split'
 
L

Larry Bates

Tempo said:
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:
[<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
said:

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
 
D

Dennis Lee Bieber

Tempo wrote:
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:

Given that "ResultSet" mention, I'd be tempted to suspect these are
being extracted from some sort of RDBM that has a misformed X(HT)ML
representation.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top