3 ms·
My guess was Moby Dick, and thought I was right when I saw there was a version made that year. I was wrong: >>> import urllib, re, md5 >>> text = urllib.ur
by dalke 11y ago
My guess was Moby Dick, and thought I was right when I saw there was a version made that year. I was wrong:
>>> import urllib, re, md5
>>> text = urllib.urlopen("http://en.wikipedia.org/wiki/1956_in_film").read()
>>> pat = re.compile(r">(\w+\s\w+)</a></i>")
>>> for title in pat.findall(text):
... if md5.new(title).hexdigest() == '0c9fc7b0723925183380b55e348462a9':
... print title
...
- JoshTriplett 11y agoSimpler version, without having to parse HTML with regexes: >>> import lxml.etree, urllib2, hashlib >>> for a in lxml.etree.parse(urllib2.urlopen("https://en.wikipedia.org/wiki/1956_in_film")).xpath("//a"): ... if a.text and hashlib.md5(a.text.strip().encode('utf-8')).hexdigest() == '0c9fc7b0723925183380b55e348462a9': ... print a.text ...
- dalke 11y agoDidn't have lxml installed. Or Beautiful Soup. "The best camera is the one you have with you." :)
- TheLoneWolfling 11y agoParsing HTML with a regex? That way lies ₥áδñèƨƨ.
- dalke 11y agoParsing Unicode without normalization (as JoshTriplett's solution) is another sort of mádness. (Or is that mádness?) In this case there's an oracle that tells me if I have the right answer, so there wasn't need for anything more rigorous. (Edit: looks like my LATIN SMALL LETTER A WITH ACUTE vs. my LATIN SMALL LETTER A + COMBINING ACUTE ACCENT didn't make it all the way through the system. Haven't researched to figure out where the normalization occurred.)