Created
November 21, 2016 22:14
-
-
Save machinefriendly/732313ec1e2ebbc4d9a608ea496b73f6 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
from multiprocessing import Pool | |
import requests | |
from requests.exceptions import ConnectionError | |
def scrape(url): | |
try: | |
print requests.get(url) | |
except ConnectionError: | |
print 'Error Occured ', url | |
finally: | |
print 'URL ', url, ' Scraped' | |
if __name__ == '__main__': | |
pool = Pool(processes=3) | |
urls = [ | |
'https://www.baidu.com', | |
'http://www.meituan.com/', | |
'http://blog.csdn.net/', | |
'http://xxxyxxx.net' | |
] | |
pool.map(scrape, urls) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment