Simple script to doing get request loops.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

getloop.py 988B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/python3.6
  2. # imports.
  3. import requests
  4. # Variables.
  5. number = 0
  6. url = ''
  7. # Start.
  8. def start():
  9. global url
  10. global number
  11. url = input('Input URL: ')
  12. if url == '':
  13. print('Error: Please enter an valid URL.')
  14. inputNumber = input('Input number of requests: ')
  15. if not isNumber(inputNumber):
  16. print('Error: Please enter an valid number.')
  17. start()
  18. number = int(inputNumber)
  19. run()
  20. # Run.
  21. def run():
  22. global url
  23. global number
  24. print('Start Requests')
  25. index = 0
  26. while index < number:
  27. request = requests.get(url=url)
  28. index += 1
  29. if request.status_code != 200:
  30. print ('Error: Wrong response ( Status code: ', request, ' ).')
  31. start()
  32. print('Request:', index)
  33. print('End Requests')
  34. start()
  35. # If variable is a number.
  36. def isNumber(value):
  37. try:
  38. float(value)
  39. return True
  40. except ValueError:
  41. return False
  42. # Start.
  43. start()