从 URL python 中删除 HTTP 和 WWW [英] Removing HTTP and WWW from URL python
本文介绍了从 URL python 中删除 HTTP 和 WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
url1='www.google.com'
url2='http://www.google.com'
url3='http://google.com'
url4='www.google'
url5='http://www.google.com/images'
url6='https://www.youtube.com/watch?v=6RB89BOxaYY
如何在 Python 中从 url 中去除 http(s)
和 www
?
How to strip http(s)
and www
from url in Python?
推荐答案
你可以使用 regex
url = 'http://www.google.com/images'
url = url.replace("http://www.","")
print url
或者你可以使用正则表达式
import re
url = re.compile(r"https?://(www\.)?")
url.sub('', 'http://www.google.com/images').strip().strip('/')
这篇关于从 URL python 中删除 HTTP 和 WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文