Muss ich HTML Tags (<i></u><table>) bei einem RegExp Ausdruck irgenwie escapen oder gibts da etwas wichtiges zu beachten ?
Denn wenn ich danach suche, wird nie etwas gefunden.
Gruss, möge die Python Community gedeihen

Nein, die Zeichen haben bei Regexps keine Sonderbedeutung. Das stimmt nicht ganz für < und >, aber da müsstest Du schon ganz seltsame Regexps gebastelt haben.MacEvil hat geschrieben:Muss ich HTML Tags (<i></u><table>) bei einem RegExp Ausdruck irgenwie escapen oder gibts da etwas wichtiges zu beachten ?
Code: Alles auswählen
import urllib, re, string
yahoo = urllib.urlopen('http://search.yahoo.com/search?fr=fp-pull-web-t&p=bush')
gfind = re.findall("<u>["+string.printable+"]{0,100}</u>",yahoo.read())
print gfind
Code: Alles auswählen
<div id=web>
<ol start=1>
<li><a class=rt href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS1/R=1/SS=53736303/H=1/*-http://www.whitehouse.gov/president/">President George W. <b>Bush</b></a>
<a href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS1/R=1/SS=53736303/NW=1/H=1/*-http://www.whitehouse.gov/president/" target=_blank><img src=http://us.i1.yimg.com/us.yimg.com/i/s/nw.gif height=11 width=11 class=nwimg alt="Open this result in new window"></a>
<br>takes a look inside the Oval Office and includes a biography of the President, a video tour, information on the latest policy initiatives. From the official White House site.<br><span class=yscat> Category:</span> <a href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS2/R=1/CS=38028355/*-http://dir.yahoo.com/Government/U_S__Government/Executive_Branch/George_W__Bush_Administration/Bush__George_W____President/">President George W. <b>Bush</b></a><br>
<u>www.whitehouse.gov/president/</u>
- <a href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS3/R=1/*-http://search.yahoo.com/search?p=bush&&fr=fp-pull-web-t&vst=0&vs=www.whitehouse.gov">More pages from this site</a>
<li><a class=rt href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS1/R=2/SS=136593/H=1/*-http://www.whitehouse.gov/">The White House</a>
<a href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS1/R=2/SS=136593/NW=1/H=1/*-http://www.whitehouse.gov/" target=_blank><img src=http://us.i1.yimg.com/us.yimg.com/i/s/nw.gif height=11 width=11 class=nwimg alt="Open this result in new window"></a>
<br>features statements and press releases by President George W. <b>Bush</b> as well as documents, an index of government information, history, and tour information.<br><span class=yscat> Category:</span> <a href="http://rds.yahoo.com/S=2766679/K=bush/v=2/SID=e/l=WS2/R=2/CS=136591/*-http://dir.yahoo.com/Government/U_S__Government/Executive_Branch/White_House__The/">U.S. Government & The White House</a><br>
<u>www.whitehouse.gov/</u>
- <u>34k</u>
Und wo hast Du den her? Aus yahoo.read() (bei mir ohne <u></u>) oder aus Deinem Browser (bei mir mit <u></u>)?MacEvil hat geschrieben:Also der erste Treffer im Quellcode sieht bei mir so aus :
Ja, aber u.U. musst Du den Server austricksen. Mach mal vorm urlopen einMacEvil hat geschrieben: Aber kann ich Suchmaschinen nun gleich von Python aus benutzen ?
Geht auch. <u>.{0,100}</u> oder <u>.{0,100}?</u>, je nachdem, was Du genau erkennen willst.MacEvil hat geschrieben:Bei der Variante mit *? Kann man aber nicht angeben wie viel mal