Created
March 31, 2017 13:23
-
-
Save willingc/46276eea8fa6f3bc83128628e636d818 to your computer and use it in GitHub Desktop.
Get a list of Adafruit tutorials for a particular category
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
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "### Adafruit Tutorials\n", | |
| "\n", | |
| "This notebook gets the urls for every tutorial in a particular\n", | |
| "Adafruit Learn category." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 171, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from bs4 import BeautifulSoup\n", | |
| "import requests" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 172, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "category_name = 'feather'\n", | |
| "\n", | |
| "prefix = 'https://learn.adafruit.com'\n", | |
| "category_url = prefix + '/category/' + category_name + '.html'" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 173, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "r = requests.get(category_url)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 174, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "soup = BeautifulSoup(r.content, 'html.parser')\n", | |
| "# print(soup.prettify())" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 175, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# find total pages\n", | |
| "last_page = soup.find('li', class_='last-page')\n", | |
| "snippet = last_page.a['href']\n", | |
| "num_pages = snippet[-1:]\n", | |
| "int_num_pages = int(num_pages)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 176, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "results = soup.find_all('div', class_='title')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 177, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# results[0].a['href']\n", | |
| "# results[0].find(class_=\"tagline\"))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 178, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# find all tutorials\n", | |
| "tutorials = []\n", | |
| "\n", | |
| "for page in range(1, int_num_pages):\n", | |
| " url = category_url[:-5] + '?guide_page=' + str(page)\n", | |
| " r = requests.get(url)\n", | |
| " c = r.content\n", | |
| " soup = BeautifulSoup(c, 'html.parser')\n", | |
| " \n", | |
| " for row in soup.find_all('h5'):\n", | |
| " item = {}\n", | |
| " item = prefix + row.a['href']\n", | |
| " tutorials.append(item)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 179, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0 https://learn.adafruit.com/magic-wand\n", | |
| "1 https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide\n", | |
| "2 https://learn.adafruit.com/toy-car-speed-timer\n", | |
| "3 https://learn.adafruit.com/adabox003\n", | |
| "4 https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity\n", | |
| "5 https://learn.adafruit.com/adafruit-io-basics-servo\n", | |
| "6 https://learn.adafruit.com/adafruit-io-basics-color\n", | |
| "7 https://learn.adafruit.com/adafruit-io-basics-analog-output\n", | |
| "8 https://learn.adafruit.com/adafruit-io-basics-analog-input\n", | |
| "9 https://learn.adafruit.com/bluetooth-le-midi-controller\n", | |
| "10 https://learn.adafruit.com/ios-switch-control-using-ble\n", | |
| "11 https://learn.adafruit.com/kombucha-thermostat-with-circuitpython-and-feather\n", | |
| "12 https://learn.adafruit.com/make-a-simple-debugging-featherwing-for-the-m0\n", | |
| "13 https://learn.adafruit.com/mystery-box-crypto-countdown-case\n", | |
| "14 https://learn.adafruit.com/adabox-001-temperature-alarm\n", | |
| "15 https://learn.adafruit.com/custom-wireless-bluetooth-cherry-mx-gamepad\n", | |
| "16 https://learn.adafruit.com/adafruit-music-maker-featherwing\n", | |
| "17 https://learn.adafruit.com/wireless-untztrument-using-ble-midi\n", | |
| "18 https://learn.adafruit.com/easy-alexa-or-echo-control-of-your-esp8266-huzzah\n", | |
| "19 https://learn.adafruit.com/schluff-the-oshw-sleep-monitor\n", | |
| "20 https://learn.adafruit.com/adafruit-2-4-tft-touch-screen-featherwing\n", | |
| "21 https://learn.adafruit.com/mac-address-finder\n", | |
| "22 https://learn.adafruit.com/mad-science-test-tube-rack\n", | |
| "23 https://learn.adafruit.com/debugging-the-samd21-with-gdb\n", | |
| "24 https://learn.adafruit.com/adabox001\n", | |
| "25 https://learn.adafruit.com/adafruit-adalogger-featherwing\n", | |
| "26 https://learn.adafruit.com/light-of-your-life-wedding-bouquet\n", | |
| "27 https://learn.adafruit.com/radio-featherwing\n", | |
| "28 https://learn.adafruit.com/adafruit-io-basics-esp8266-arduino\n", | |
| "29 https://learn.adafruit.com/adafruit-power-relay-featherwing\n", | |
| "30 https://learn.adafruit.com/mindfulness-clock-of-doom\n", | |
| "31 https://learn.adafruit.com/adafruit-stepper-dc-motor-featherwing\n", | |
| "32 https://learn.adafruit.com/adafruit-wiz5500-wiznet-ethernet-featherwing\n", | |
| "33 https://learn.adafruit.com/aws-iot-and-adafruit-wiced-feather\n", | |
| "34 https://learn.adafruit.com/adafruit-feather-m0-radio-with-rfm69-packet-radio\n", | |
| "35 https://learn.adafruit.com/adafruit-8-channel-pwm-or-servo-featherwing\n", | |
| "36 https://learn.adafruit.com/feather-weather-lamp\n", | |
| "37 https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module\n", | |
| "38 https://learn.adafruit.com/dotstar-dauntless-gauntlets\n", | |
| "39 https://learn.adafruit.com/build-a-cloud-connected-esp8266-power-meter\n", | |
| "40 https://learn.adafruit.com/adafruit-15x7-7x15-charlieplex-led-matrix-charliewing-featherwing\n", | |
| "41 https://learn.adafruit.com/adafruit-8x16-led-matrix-featherwing\n", | |
| "42 https://learn.adafruit.com/3d-printed-star-trek-communicator\n", | |
| "43 https://learn.adafruit.com/adafruit-ultimate-gps-featherwing\n", | |
| "44 https://learn.adafruit.com/14-segment-alpha-numeric-led-featherwing\n", | |
| "45 https://learn.adafruit.com/7-segment-display-internet-clock\n", | |
| "46 https://learn.adafruit.com/adafruit-7-segment-led-featherwings\n", | |
| "47 https://learn.adafruit.com/adafruit-oled-featherwing\n", | |
| "48 https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module\n", | |
| "49 https://learn.adafruit.com/wifi-pixie-cyberwig-wearable-visualization\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "for n in range(0, len(tutorials)):\n", | |
| " print(n, tutorials[n])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 182, | |
| "metadata": { | |
| "collapsed": false, | |
| "deletable": true, | |
| "editable": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# Alphabetical sort\n", | |
| "tutorials.sort()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 183, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0 https://learn.adafruit.com/14-segment-alpha-numeric-led-featherwing\n", | |
| "1 https://learn.adafruit.com/3d-printed-star-trek-communicator\n", | |
| "2 https://learn.adafruit.com/7-segment-display-internet-clock\n", | |
| "3 https://learn.adafruit.com/adabox-001-temperature-alarm\n", | |
| "4 https://learn.adafruit.com/adabox001\n", | |
| "5 https://learn.adafruit.com/adabox003\n", | |
| "6 https://learn.adafruit.com/adafruit-15x7-7x15-charlieplex-led-matrix-charliewing-featherwing\n", | |
| "7 https://learn.adafruit.com/adafruit-2-4-tft-touch-screen-featherwing\n", | |
| "8 https://learn.adafruit.com/adafruit-7-segment-led-featherwings\n", | |
| "9 https://learn.adafruit.com/adafruit-8-channel-pwm-or-servo-featherwing\n", | |
| "10 https://learn.adafruit.com/adafruit-8x16-led-matrix-featherwing\n", | |
| "11 https://learn.adafruit.com/adafruit-adalogger-featherwing\n", | |
| "12 https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module\n", | |
| "13 https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module\n", | |
| "14 https://learn.adafruit.com/adafruit-feather-m0-radio-with-rfm69-packet-radio\n", | |
| "15 https://learn.adafruit.com/adafruit-io-basics-analog-input\n", | |
| "16 https://learn.adafruit.com/adafruit-io-basics-analog-output\n", | |
| "17 https://learn.adafruit.com/adafruit-io-basics-color\n", | |
| "18 https://learn.adafruit.com/adafruit-io-basics-esp8266-arduino\n", | |
| "19 https://learn.adafruit.com/adafruit-io-basics-servo\n", | |
| "20 https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity\n", | |
| "21 https://learn.adafruit.com/adafruit-music-maker-featherwing\n", | |
| "22 https://learn.adafruit.com/adafruit-oled-featherwing\n", | |
| "23 https://learn.adafruit.com/adafruit-power-relay-featherwing\n", | |
| "24 https://learn.adafruit.com/adafruit-stepper-dc-motor-featherwing\n", | |
| "25 https://learn.adafruit.com/adafruit-ultimate-gps-featherwing\n", | |
| "26 https://learn.adafruit.com/adafruit-wiz5500-wiznet-ethernet-featherwing\n", | |
| "27 https://learn.adafruit.com/aws-iot-and-adafruit-wiced-feather\n", | |
| "28 https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide\n", | |
| "29 https://learn.adafruit.com/bluetooth-le-midi-controller\n", | |
| "30 https://learn.adafruit.com/build-a-cloud-connected-esp8266-power-meter\n", | |
| "31 https://learn.adafruit.com/custom-wireless-bluetooth-cherry-mx-gamepad\n", | |
| "32 https://learn.adafruit.com/debugging-the-samd21-with-gdb\n", | |
| "33 https://learn.adafruit.com/dotstar-dauntless-gauntlets\n", | |
| "34 https://learn.adafruit.com/easy-alexa-or-echo-control-of-your-esp8266-huzzah\n", | |
| "35 https://learn.adafruit.com/feather-weather-lamp\n", | |
| "36 https://learn.adafruit.com/ios-switch-control-using-ble\n", | |
| "37 https://learn.adafruit.com/kombucha-thermostat-with-circuitpython-and-feather\n", | |
| "38 https://learn.adafruit.com/light-of-your-life-wedding-bouquet\n", | |
| "39 https://learn.adafruit.com/mac-address-finder\n", | |
| "40 https://learn.adafruit.com/mad-science-test-tube-rack\n", | |
| "41 https://learn.adafruit.com/magic-wand\n", | |
| "42 https://learn.adafruit.com/make-a-simple-debugging-featherwing-for-the-m0\n", | |
| "43 https://learn.adafruit.com/mindfulness-clock-of-doom\n", | |
| "44 https://learn.adafruit.com/mystery-box-crypto-countdown-case\n", | |
| "45 https://learn.adafruit.com/radio-featherwing\n", | |
| "46 https://learn.adafruit.com/schluff-the-oshw-sleep-monitor\n", | |
| "47 https://learn.adafruit.com/toy-car-speed-timer\n", | |
| "48 https://learn.adafruit.com/wifi-pixie-cyberwig-wearable-visualization\n", | |
| "49 https://learn.adafruit.com/wireless-untztrument-using-ble-midi\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "for n in range(0, len(tutorials)):\n", | |
| " print(n, tutorials[n])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.6.0" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment