Created
July 10, 2020 19:54
-
-
Save dtaivpp/824f6587e2667889ed422e0490561df1 to your computer and use it in GitHub Desktop.
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
import threading | |
import requests | |
sites = { | |
'site1.com': ['https://site1.com/page1' ...], | |
'site2.com': ['https://site2.com/page1' ...], | |
'site3.com': ['https://site3.com/page1' ...], | |
'site4.com': ['https://site4.com/page1' ...] | |
} | |
def process(url_list) | |
for url in url_list: | |
response = requests.get(url) | |
do_something_with_response(response) | |
threads = [] | |
for site, url_list in sites: | |
thread = threading.Thread(target=process, args=(url_list)) | |
threads.append(thread) | |
thread.start() | |
# Makes the program wait for threads to finish | |
for thread in threads: | |
thread.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment