Commit 677eadd3 authored by Everardo Gonzalez's avatar Everardo Gonzalez

Upload Jupyter notebook

parent e955d52d
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from urllib.request import urlopen, urlretrieve, quote\n",
"from urllib.parse import urljoin\n",
"from bs4 import BeautifulSoup"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# open and read URL\n",
"url = 'https://zenodo.org/record/1471639#.XO5GriaxUUF'\n",
"u = urlopen(url)\n",
"try:\n",
" html = u.read().decode('utf-8')\n",
"finally:\n",
" u.close()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# look for html class \"filename\" in URL and try download\n",
"\n",
"soup = BeautifulSoup(html, \"lxml\")\n",
"\n",
"\n",
"for link in soup.select('a.filename'):\n",
" href = link.get('href')\n",
" \n",
" filename = href.split('/', 1)[-1][0:-11]\n",
" filename = filename.split('/')[-1]\n",
"\n",
" href = urljoin(url, quote(href))[0:-15]\n",
" try:\n",
" urlretrieve(href, filename)\n",
" except:\n",
" print('failed to download file ' + filename)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment