对你来说听起来并不像你需要任何“模糊”匹配.而且我假设当你说“url”时你的意思是“网址指向网址的网页”.只需使用Python的内置子串搜索功能:
>>> import urllib2
>>> webpage = urllib2.urlopen('http://www.dmx.com/about/our-clients')
>>> webpage_text = webpage.read()
>>> webpage.close()
>>> for name in ['Caribou Coffee', 'Express', 'Sears']:
... if name in webpage_text:
... print name, "found!"
...
Caribou Coffee found!
Express found!
>>>
如果您担心字符串大小写不匹配,只需将其全部转换为大写.
>>> webpage_text = webpage_text.upper()
>>> for name in ['CARIBOU COFFEE', 'EXPRESS', 'SEARS']:
... if name in webpage_text:
... print name, 'found!'
...
CARIBOU COFFEE found!
EXPRESS found!