Last active
May 30, 2018 02:41
-
-
Save Luavis/e64069856fe05d654536874440600ac6 to your computer and use it in GitHub Desktop.
work with chrome driver: http://chromedriver.chromium.org/downloads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import argparse | |
from multiprocessing import Queue, Process | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
def worker(q): | |
options = Options() | |
options.add_argument('--headless') | |
options.add_argument("--window-size=1920x1080") | |
chrome_driver_path = os.path.join(os.getcwd(), "chromedriver") | |
driver = webdriver.Chrome(chrome_driver_path, chrome_options=options) | |
while not q.empty(): | |
driver.get(q.get()) | |
driver.quit() | |
def main(): | |
parser = argparse.ArgumentParser(description='Visit URL N time.') | |
parser.add_argument('url', metavar='url', type=str, | |
help='Target URL to visit') | |
parser.add_argument('-n', metavar='requests', dest='requests', type=int, | |
default=1, | |
help='Number of request to perform') | |
parser.add_argument('-c', metavar='concurrency', dest='concurrency', | |
type=int, default=1, | |
help='Number of multiple requests to make at a time') | |
args = parser.parse_args() | |
q = Queue(args.requests) | |
for _ in range(args.requests): | |
q.put(args.url) | |
processes = [] | |
for _ in range(args.concurrency): | |
p = Process(target=worker, args=(q, )) | |
processes.append(p) | |
p.start() | |
# join all process | |
for p in processes: | |
p.join() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment