Skip to content

Instantly share code, notes, and snippets.

@tacaswell
Forked from mlub/scanExamples.py
Created July 17, 2016 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacaswell/0edc759286dfd02e48f1b82a6dbad03f to your computer and use it in GitHub Desktop.
Save tacaswell/0edc759286dfd02e48f1b82a6dbad03f to your computer and use it in GitHub Desktop.
Loops over examples on the matplotlib1.5.1 page and opens the 1.5.1 and 2.0 version in a browser
#!/usr/bin/env python
import requests
import subprocess
from lxml import html
old_url = 'http://matplotlib.org/1.5.1/examples/'
new_url = 'http://matplotlib.org/2.0.0b2/examples/'
# Skip any urls containing these strings
skip_these = ['animation/', 'api/']
if __name__ == '__main__':
"""
Scan the matplotlib examples page and open the 1.5.1 version and
2.0.0b2 version
"""
old_page = requests.get(old_url+'index.html').text
old_tree = html.fromstring(old_page)
examples = old_tree.xpath('//a[@class="reference internal"]')
for ex in examples:
if 'index.html' in ex.attrib['href']:
continue
tmp=[skip for skip in skip_these if skip in ex.attrib['href']]
if len(tmp)>0:
continue
subprocess.call(['google-chrome',
old_url+ex.attrib['href'],
new_url+ex.attrib['href']])
input("%s - Press Enter to continue..." % (ex.attrib['href'],))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment