11-2-Apriori-Mining-XSS-param.py 666 B

123456789101112131415161718192021222324
  1. from model import Apriori
  2. import re
  3. def main():
  4. datasets = []
  5. with open("data/XSS/xss-2000.txt") as f:
  6. for line in f:
  7. index = line.find("?")
  8. if index > 0:
  9. line = line[index + 1:len(line)]
  10. tokens = re.split('\=|&|\?|\%3e|\%3c|\%3E|\%3C|\%20|\%22|<|>|\\n|\(|\)|\'|\"|;|:|,|\%28|\%29', line)
  11. datasets.append(tokens)
  12. # apriori 算法
  13. apriori = Apriori()
  14. frequently_itemset, support_data = apriori.apriori(datasets, 0.15)
  15. rules = apriori.generate_rules(frequently_itemset, support_data, min_reliability=1)
  16. print(rules)
  17. if __name__ == '__main__':
  18. main()