最近想提取出特定的URL,遇到问题为预期提取出URL中带有webshell或者phpinfo字段的URL,但是全部URL都匹配出来了:
for url in urls:
if "webshell" or "phpinfo" in url:
print url
改成and语句也不符合预期,只提取出了含有phpinfo的url:
for url in urls:
if "webshell" and "phpinfo" in url:
print url
That's it. You originally judged "webshell" first, and if it's not zero, then judge "phpinfo" in url. "webshell" and "phpinfo" in url are tied...
This means
if "webshell"
orif "phpinfo" in url
and the former is always true.What this means is
if "phpinfo" in url
因為if "webshell"
always established.The solution is basically as @lock said:
If there are a lot of words used to match today:
Result:
urlcontain(url, lst)
可以問url
裡面是不是有lst
Any string insideThis way you can compare ten keywords without writing too long an if statement.
Of course you have to use
re
也可以,只是我個人不太喜歡re
That’s it...Questions I answered: Python-QA