Skip to content

Instantly share code, notes, and snippets.

@machinefriendly
Created November 21, 2016 22:14
Show Gist options
  • Save machinefriendly/732313ec1e2ebbc4d9a608ea496b73f6 to your computer and use it in GitHub Desktop.
Save machinefriendly/732313ec1e2ebbc4d9a608ea496b73f6 to your computer and use it in GitHub Desktop.
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