python-3.x - 在输入文本中查找所有网站地址(Python)
问题描述
我需要在输入文本中找到所有网站地址,并按照它们在文本中出现的顺序打印所有地址,每个地址都换行。"https://" "http://" "www."
我在字符串中使用了拆分,但我不能返回以这个“www”开头的那个。有人可以向我解释我该如何解决这个问题吗?
样本输入 1:
WWW.GOOGLE.COM 使用 100% 的可再生能源,并且www.ecosia.com每 45 次搜索就种一棵树!
样本输出 1:
万维网.GOOGLE.COM
text = input()
text = text.lower()
words = text.split(" ")
for word in words:
解决方案
我要做的是捕捉“www”couse',我们知道每个网址都以它开头,并以空格键结尾,所以将所有内容放入数组中然后打印它,但是python在它的库中有很多字符串函数但是我不知道很多。
str = " www.GOOGLE.COM uses 100-percent renewable energy sources and www.ecosia.com plants a tree for every 45 searches! "
str.lower()
tmp = ""
all_url = []
k=0
for i in range(len(str)-3):
if(str[i]+str[i+1]+str[i+2] == "www"):
k=i+4
while(str[k] != " "):
tmp=tmp+str[k]
k+=1
all_url.append(tmp)
tmp = ""
i=k
for url in all_url:
print("www." + url )
推荐阅读
- ubuntu - vim 大小不是终端的全尺寸
- .net-core - 获取 Azure AD JWT 令牌以在集成测试授权时使用
- javascript - 在 Keydown 事件上它应该播放匹配的音频
- reactjs - 来自 API 的 Reactjs 头像 src
- java - 如何使用 Jackson API 解析 XML?
- python-3.x - 如何将actor输出限制在特定范围内?
- python - 当我尝试在 Windows 上安装 LocalStack 时出现此错误
- python-2.7 - EOFError 与 numpy.load()
- javascript - Highchart.js 自定义 Y 轴代码
- string - why fmt.Scanf doesn't work in golang test