【发布时间】:2016-11-04 04:59:03
【问题描述】:
我需要从一个循环中取出带有三个特定子字符串的 URL。以下代码有效,但我确信有一种更优雅的方法:
for node in soup.findAll('loc'):
url = node.text.encode("utf-8")
if "/store/" not in url and "/cell-phones/" not in url and "/accessories/" not in url:
objlist.loc.append(url)
else:
continue
谢谢!
【问题讨论】:
-
可以全部使用内置函数
标签: python if-statement conditional-statements