25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. #!/usr/bin/env python3
  2. import re
  3. from requests import Session
  4. from SLogin import SLogin
  5. class STract(SLogin):
  6. urlTract = "reg/mhsscrdet.php?tipe=nim&txt={}"
  7. extracted = []
  8. def extract(self):
  9. # check if logged in
  10. if self.success:
  11. # just a little future proofing
  12. for i in range(0, 10):
  13. raw = self.session.get(self.url + self.urlTract.format(i)).text
  14. if 'HASIL PENCARIAN DATA MAHASISWA' in raw:
  15. # use regex to find all nim
  16. raw = re.findall("([0-9]{9})", raw)
  17. # remove duplicate values using set
  18. raw = list(set(raw))
  19. # sort all the values
  20. raw = sorted(raw)
  21. # append to all extracted data
  22. self.extracted += raw
  23. return self.extracted
  24. else:
  25. raise Exception("Please login first")
  26. if __name__ == "__main__":
  27. import argparse
  28. from time import time as now
  29. start_time = now()
  30. parser = argparse.ArgumentParser()
  31. parser.add_argument("nim",
  32. help="NIM to try login")
  33. parser.add_argument("pin",
  34. help="PIN to try login")
  35. parser.add_argument("--outfile",
  36. metavar="FILE",
  37. default="temp.txt",
  38. help="outfile target")
  39. args = parser.parse_args()
  40. with STract(args.nim, args.pin) as extraction:
  41. print('Trying to login with {} {}'.format(args.nim, args.pin))
  42. if extraction.login():
  43. print('Login success, extracing data...')
  44. data = extraction.extract()
  45. print('Extraced {} data'.format(len(data)))
  46. with open(args.outfile, 'w') as output:
  47. print('Writing data to output file...')
  48. output.write("\n".join(data))
  49. print('Done in {:0.2f}s'.format(now() - start_time))
  50. else:
  51. print('Login failed')