我打算將我的一個刮板移動到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