【发布时间】:2013-12-11 06:46:49
【问题描述】:
我不知道任何 python,但我需要稍微自定义一个脚本。
脚本中解析了一些字符串并将其放入列表中(我猜)。
然后根据它们是否以“http”开头来过滤这些字符串。我要添加的是基于文件扩展名的过滤器。所有以html 或xml 结尾的链接都应被过滤掉。
这是过滤所有超链接的代码:
links = filter (lambda x:x.startswith("http://") , links)
我不知道为 .endswith(".html) OR .endswith("xml") 之类的东西放置 OR 运算符的正确语法
我知道这会过滤所有以.html 结尾的链接,但我还需要.xml 链接。
links = filter (lambda x:x.startswith("http://") , links)
links = filter (lambda x:x.endswith(".html") , links)
【问题讨论】:
-
那些以可选协议规范开头的字符串不是hyperlinks,而是URLs。