is there a safe/easy way to search and replace text w/in an html page?

Darrell news at dorb.com
Sun Nov 28 20:40:44 CET 1999


The attached code isn't very well tested.
And I'm sure as always that someone else will point out that this was
possible
from the lib :)

--
--Darrell

"Levi Cook" <levicook at earthlink.net> wrote in message
news:3840593B.2D1A2E30 at earthlink.net...
> Hello,
>
> I'm new to python and I've been tasked w/ writing a script that fetches
> a web-page and highlights the term that the user searched for. Passing
> the URL and search term to my script was a cinch and fetching the page
> was also quite easy.
>
> The crux of my problem lies with establishing a strategy for searching
> out the users term and replacing it with css tags surrounding the
> original term.
> At first glance the re module seemed sufficient (and maybe still is ),
> but it doesn't really have any knowledge of HTML semantics. My next
> venture was to look at the htmllib module. This appears to parse the
> html fine, but i'm still at a bit of a loss on what this actually does
> for me, particularly how do I get my parser to output my page.
>
> Does anyone know where I can find code that does anything remotely like
> this?
> Does anyone know where I can find good reference on the htmllib module,
> the python library reference is pretty bleak in this area.
>
> Thanks in advance for you time and help.
> Levi Cook
> levicook at earthlink.net



begin 666 url.py
M:6UP;W)T('5R;&QI8BP@<F4L(&AT='!L:6(L(&)I<V5C= T*#0I?7W-E<4YU
M;3TP#0ID968 at 7V9I;F1A;&Q%>'0H<&%T=&5R;BP@<V]U<F-E+"!S=&%R=#TP
M+"!S=&]P/3 I. at T*(" @(" @(" B(B)2971U<FX at 82!L:7-T(&]F(&%L;"!N
M;VXM;W9E<FQA<'!I;F<@;6%T8VAE<R!I;B!T:&4@<W1R:6YG+ at T*#0H@(" @
M(" @($EF(&]N92!O<B!M;W)E(&=R;W5P<R!A<F4@<')E<V5N="!I;B!T:&4@
M<&%T=&5R;BP@<F5T=7)N(&$-"B @(" @(" @;&ES="!O9B!G<F]U<',[('1H
M:7,@=VEL;"!B92!A(&QI<W0@;V8@='5P;&5S(&EF('1H92!P871T97)N#0H@
M(" @(" @(&AA<R!M;W)E('1H86X@;VYE(&=R;W5P+ at T*#0H@(" @(" @($5M
M<'1Y(&UA=&-H97, at 87)E(&EN8VQU9&5D(&EN('1H92!R97-U;'0N#0H-"B @
M(" @(" @4F5T=7)N<R!A(&QI<W0@;V8 at 6RAS=&%R="P@<V5Q3G5M8F5R+"!E
M;F0I+"XN+ET-"@T*(" @(" @(" ^/CX@<S$])V%X8GAC>&%X8GAC>"<-"B @
M(" @(" @/CX^(&9I;F1A;&Q%>'0H)V$N*C]B+BH_8R<L<S$I#0H@(" @(" @
M(%LH,"P@,"P at -2DL("@V+" Q+" Q,2E=#0H@(" @(" @("(B(@T*(" @(" @
M("!G;&]B86P at 7U]S97%.=6T-"B @(" @(" @<&]S(#T@<W1A<G0-"B @(" @
M(" @:68@<W1O<#T],#H-"B @(" @(" @(" @(" @("!E;F0];&5N*'-O=7)C
M92D-"B @(" @(" @96QS93H-"B @(" @(" @(" @(" @("!E;F0@/2!M:6XH
M<W1O<"QL96XH<V]U<F-E*2D-"B @(" @(" @<F5S=6QT<R ](%M=#0H@(" @
M(" @(&UA=&-H(#T@<&%T=&5R;BYC;V1E+FUA=&-H#0H@(" @(" @(&%P<&5N
M9" ](')E<W5L=',N87!P96YD#0H@(" @(" @('=H:6QE('!O<R \/2!E;F0Z
M#0H@(" @(" @(" @(" @(" @<F5G<R ](&UA=&-H*'-O=7)C92P@<&]S+"!E
M;F0L(# I#0H@(" @(" @(" @(" @(" @:68@;F]T(')E9W,Z#0H@(" @(" @
M(" @(" @(" @(" @(" @("!B<F5A:PT*(" @(" @(" @(" @(" @(&DL(&H@
M/2!R96=S6S!=#0H@(" @(" @(" @(" @(" @<F5S=" ](')E9W-;,3I=#0H@
M(" @(" @(" @(" @(" @:68@;F]T(')E<W0Z#0H@(" @(" @(" @(" @(" @
M(" @(" @("!G<B ]("AI+%]?<V5Q3G5M+&HI#0H@(" @(" @(" @(" @(" @
M96QI9B!L96XH<F5S="D@/3T@,3H-"B @(" @(" @(" @(" @(" @(" @(" @
M(&$L(&(@/2!R97-T6S!=#0H@(" @(" @(" @(" @(" @(" @(" @("!G<B ]
M("AA+%]?<V5Q3G5M+&(I#0H@(" @(" @(" @(" @(" @96QS93H-"B @(" @
M(" @(" @(" @(" @(" @(" @(&=R(#T at 6UT-"B @(" @(" @(" @(" @(" @
M(" @(" @(&9O<B H82P at 8BD@:6X@<F5S=#H-"B @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @9W(N87!P96YD*"AA+&(I*0T*(" @(" @(" @(" @
M(" @(" @(" @(" @9W(@/2!T=7!L92AG<BD-"B @(" @(" @(" @(" @("!A
M<'!E;F0H9W(I#0H@(" @(" @(" @(" @(" @7U]S97%.=6T]7U]S97%.=6TK
M,0T*(" @(" @(" @(" @(" @('!O<R ](&UA>"AJ+"!P;W,K,2D-"B @(" @
M(" @<F5T=7)N(')E<W5L=',-"@T*#0ID968 at 9V5T06QL5&%G<RAD871A*3H-
M"B @("!R971U<FX at 7V9I;F1A;&Q%>'0H<F4N8V]M<&EL92 at G/%M>/ETJ/SXG
M*2P at 9&%T82D-"@T*#0H-"G-T87)T5&%G(#T@)SQF;VYT(&-L87-S(#T@:&EG
M:&QI9VAT/CQS=')O;F<^)PT*96YD5&%G(#T@)SPO<W1R;VYG/CPO9F]N=#XG
M#0IC<W-486<@/2 G/'-T>6QE('1Y<&4](G1E>'0O8W-S(CXN:&EG:&QI9VAT
M('MB86-K9W)O=6YD+6-O;&]R.B-&1D9&.3E]/"]S='EL93XG#0IS;W5R8V4]
M)VAT=' Z+R]P87!A:F\N8V]M)PT*#0IA9&1R97-S(#T@=7)L;&EB+G%U;W1E
M*'-O=7)C92D-"@T*861D<F5S<R ]('5R;&QI8BYU;G%U;W1E*&%D9')E<W,I
M#0ID871A/2!U<FQL:6(N=7)L;W!E;BAS;W5R8V4I+G)E860H*0T*#0HC(&EN
M<V5R=" \8F%S93X@<V\@=&AA="!A;&P at 96UB961E9"!54DPG<R!R97-O;'9E
M(&-O<G)E8W1L>0T*=&5R;7-T<FEN9R ]("<H/VUI*5Y<<RH\:&5A9#Y<<RHG
M#0IT97)M<&%T(#T@<F4N8V]M<&EL92AT97)M<W1R:6YG*0T*9&%T82 ]('1E
M<FUP870N<W5B*"<\:&5A9#Y<;CQB87-E(&AR968](B5S(CY<;B5S)UP-"B @
M(" E*&%D9')E<W,L8W-S5&%G*2P at 9&%T82D-"@T*#0H@(" @(R!&:6YD(&%L
M;"!T86=S('-O('=E(&-A;B!A=F]I9"!S8W)E=VEN9R!T:&5M('5P#0IA;&Q4
M86=S/6=E=$%L;%1A9W,H9&%T82D-"@T*9&5F(')E<"AM;RDZ#0H@(" @(B(B
M#0H@(" @1&]N)W0@<&5R9F]R;2!R97!L86-E<R!I;G-I9&4@;V8@=&%G<PT*
M(" @("(B(@T*(" @(&D@/2!B:7-E8W0N8FES96-T*&%L;%1A9W,L(&UO+G-P
M86XH*2DM,0T*(" @(&EF(&D@/B P(&%N9"!A;&Q486=S6VE=6S!=(#P](&UO
M+G-P86XH*5LP75P-"B @(" @(" @(&%N9"!A;&Q486=S6VE=6S)=(#X](&UO
M+G-P86XH*5LQ73H-"B @(" @(" @<F5T=7)N(&UO+F=R;W5P*# I#0H-"B @
M("!N97=3=')I;F<](B5S)7,E<R(E*'-T87)T5&%G+&UO+F=R;W5P*#$I+&5N
M9%1A9RD-"B @("!R971U<FX@;F5W4W1R:6YG#0H-"G!A=#UR92YC;VUP:6QE
M*"<H8V]M*2<I#0ID871A,3UP870N<W5B*')E<"P at 9&%T82D-"@T*;W!E;B at G
@9&%T82YH=&UL)RPG=R<I+G=R:71E*&1A=&$Q*0T*#0H`
`
end





More information about the Python-list mailing list