我打算将我的一个刮板移动到Python。我很喜欢在PHP中使用preg_match
和preg_match_all
。我在Python中找不到类似于preg_match
的合适函数。任何人都可以帮我这么做吗?对应于PHP的preg_match的Python
例如,如果我想获得<a class="title"
和</a>
之间的内容,我用下面的函数在PHP中:
preg_match_all('/a class="title"(.*?)<\/a>/si',$input,$output);
而在Python我无法找出一个类似的功能。
这里是pyt hon正则表达式文档:http://docs.python.org/howto/regex.html – 2012-01-30 09:39:24
在Python中,我们不使用正则表达式来解析HTML,我们使用[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup /)。见http://stackoverflow.com/a/1732454/78845 – Johnsyweb 2012-01-30 09:44:12