[Tutor] Text manipulation problem

McCarney, James Alexander James.Alexander.McCarney@Cognicase.com
Wed Nov 27 13:41:59 2002


I have this kind of code (mixture of JavaScript and HTML), which is compiled
into an HTML help file.


<p>Test text <a 
		class=popupspot 
		href="JavaScript:hhctrl.TextPopup('My silly
pop-up','Arial,8',10,10,00000000,0xc0ffff)">
		pop-up</a> 
 		here.</p>


What I want to do is go to my directory...
Get all the text where there is an <a class=popupspot href=" .... etc. ...
</a> 

(Magnus showed me the import re and regular expression stuff-- thank you
thank you!)


Then I want to take the text and convert it to an HTML table. See way below
for the table mess.

Here is my logic (Cartesianism is not my forte! ;-)

#egregiously erroneous pseudo-code alert
import sys, string, os, os.path, glob, re #all the stuff to do the
manipulation

def gettextpopup():
	"""Find JavaScript text pop-ups in HTML and convert to table."""

	prompt=raw_input("Go to where I want")
	prompt.chdir #now where i want to be

	prompt2=raw_input("what files do i want")
	glob the files...

	prompt3=raw_input("do I want to start converting? y/n")
	if prompt3=='y':
		re.compile (insert reg expr here) #whatever it will be
		re.findall
	elif prompt3='n': print "Thanks for dropping by."

So compiling the re object is ok (sort of) for me...

What I need to do is take the previously listed html, and convert it into
the table mess... keeping the different text sandwiched between the tags
integral.



<!--(Table)=========================================================-->
<table x-use-null-cells
		style="x-cell-content-align: top;
				width: 100%;
				border-spacing: 0;"
		cellspacing=0
		width=100%>
<col style="width: 17.362%;">
<col style="width: 82.638%;">

<tr valign=top>
<td style="border-left-width: 1px;
			border-left-color: #000000;
			border-left-style: Solid;
			border-top-style: Solid;
			border-top-color: #000000;
			border-top-width: 1px;
			border-right-width: 1px;
			border-right-color: #000000;
			border-right-style: Solid;
			border-bottom-style: Solid;
			border-bottom-color: #000000;
			border-bottom-width: 1px;
			padding-right: 10px;
			padding-left: 10px;"
	width=17.362%>
<p>My silly pop-up</td>
<td style="border-top-style: Solid;
			border-top-color: #000000;
			border-top-width: 1px;
			border-right-width: 1px;
			border-right-color: #000000;
			border-right-style: Solid;
			border-bottom-style: Solid;
			border-bottom-color: #000000;
			border-bottom-width: 1px;
			padding-right: 10px;
			padding-left: 10px;"
	width=82.638%>
<p>Test text pop-up here.</td></tr>
</table>
	



James Alexander McCarney, technical writer, (450) 928-3386 x2262 
COGNICASE-M3i http://www.m3isystems.com
mailto:James.Alexander.McCarney@Cognicase.com
1111 Saint-Charles Avenue West, 11th Floor, East Tower, Longueuil, Quebec,
J4K 5G4 Canada