Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

regex help

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


david.bramer at googlemail

Jul 8, 2009, 3:06 PM

Post #1 of 1 (197 views)
Permalink
regex help

Hi

I have a few regexs I need to do, but im struggling to come up with a
nice way of doing them, and more than anything am here to learn some
tricks and some neat code rather than getting an answer - although
thats obviously what i would like to get to.

Problem 1 -

<span class="chg"
id="ref_678774_cp">(25.47%)</span><br>

I want to extract 25.47 from here - so far I've tried -

xPer = re.search('<span class="chg" id="ref_"'+str(xID.group(1))+'"_cp
\">(.*?)%', content)

and

xPer = re.search('<span class=\"chg\" id=\"ref_"+str(xID.group(1))+"_cp
\">\((\d*)%\)</span><br>', content)

neither of these seem to do what I want - am I not doing this
correctly? (obviously!)

Problem 2 -

<td>&nbsp;</td>

<td width="1%" class=key>Open:
</td>
<td width="1%" class=val>5.50
</td>
<td>&nbsp;</td>
<td width="1%" class=key>Mkt Cap:
</td>
<td width="1%" class=val>6.92M
</td>
<td>&nbsp;</td>
<td width="1%" class=key>P/E:
</td>
<td width="1%" class=val>21.99
</td>


I want to extract the open, mkt cap and P/E values - but apart from
doing loads of indivdual REs which I think would look messy, I can't
think of a better and neater looking way. Any ideas?

Cheers

David

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.