2016-09-26 25 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