限制搜索(python)

时间:2011-04-12 07:37:41

标签: python string search asp.net-web-api

from shodan import WebAPI

SHODAN_API_KEY = "MY API KEY"
api = WebAPI(SHODAN_API_KEY)

results = api.exploitdb.search('PHP')

print 'Results found: %s' % results['total']
for exploit in results['matches']:
        print '%s:' % (exploit['description'])

如何将搜索限制为仅打印前5个结果?

2 个答案:

答案 0 :(得分:5)

for exploit in results['matches'][:5]:
        print '%s:' % (exploit['description'])

答案 1 :(得分:0)

花点时间学习有关列表和“切片”的Python基础知识:

http://diveintopython.ep.io/native-datatypes.html