2016-09-26 26 views
-2

我需要將鏈接src,css,href,html頁面並將它們保存到文本文件中。如何使正則表達式帶我href,src,css鏈接python

我需要處理正則表達式(正則表達式)。 謝謝!

+4

你應該嘗試點什麼 –

+0

我們在這裏做的是告訴你爲什麼你的代碼不是炒作。沒有代碼?不能幫助... – holdenweb

+0

你可以通過那裏http://stackoverflow.com/questions/499345/regular-expression-to-extract-url-from-an-html-link –

回答

0
import re 

p = re.compile(ur'.*(src|css|href|a html).*') 

test_str1 = '<a html>' 
test_str2 = 'String without any tags' 

if re.match(p, test_str1) is not None: 
    print test_str1 

if re.match(p, test_str2) is not None: 
    print test_str2 
>> <a html> 

這裏是Python 2.7版, 一個解決方案,我認爲你理解了正則表達式的一部分,但如果不是在這裏是一個很好的教程site,你可以用它來測試你的正則表達式。

+0

我忘了提到,蟒蛇是版本3.5:/ – Mangux