Saving search results in a dictionary

Lukas Holcik xholcik1 at fi.muni.cz
Thu Jun 17 16:00:25 CEST 2004


Hi everyone!

How can I simply search text for regexps (lets say <a 
href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a 
dictionary { name : URL}? In a single pass if it could.

Or how can I replace the html &entities; in a string 
"blablabla&amp;blablabal&amp;balbalbal" with the chars they mean using 
re.sub? I found out they are stored in an dict [from htmlentitydefs import 
htmlentitydefs]. I though about this functionality:

regexp = re.compile("&[a-zA-Z];")
regexp.sub(entitydefs[r'\1'], url)

but it can't work, because the r'...' must eaten directly by the sub, and 
cannot be used so independently ( at least I think so). Any ideas? Thanks 
in advance.

-i

---------------------------------------_.)--
|  Lukas Holcik (xholcik1 at fi.muni.cz)  (\=)*
----------------------------------------''--



More information about the Python-list mailing list