小编tno*_*sky的帖子

在Python中使用多个NOT IN语句

我需要一个循环中带有三个特定特定子串的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
Run Code Online (Sandbox Code Playgroud)

谢谢!

python if-statement conditional-statements

4
推荐指数
1
解决办法
4574
查看次数