Category Archives: Web

A Simple Intro to Web Scraping with Python

Web scraping is where a programmer will write an application to download web pages and parse out specific information from them. Usually when you are scraping data you will need to make your application navigate the website programmatically. In this chapter, we will learn how to download files from the internet and parse them if need be. We will also learn how to create a simple spider that we can use to crawl a website.

Tips for Scraping

There are a few tips that we need to go over before we start scraping.

  • Always check the website’s terms and conditions before you scrape them. They usually have terms that limit how often you can scrape or what you can you scrape
  • Because your script will run much faster than a human can browse, make sure you don’t hammer their website with lots of requests. This may even be covered in the terms and conditions of the website.
  • You can get into legal trouble if you overload a website with your requests or you attempt to use it in a way that violates the terms and conditions you agreed to.
  • Websites change all the time, so your scraper will break some day. Know this: You will have to maintain your scraper if you want it to keep working.
  • Unfortunately the data you get from websites can be a mess. As with any data parsing activity, you will need to clean it up to make it useful to you.

With that out of the way, let’s start scraping!

Continue reading A Simple Intro to Web Scraping with Python

Using pyGal Graphs in Flask

I recently took on a project where I needed to graph some data on a webpage using data I had queried from a database. Since I love Python, I decided to use it to accomplish this task. I went with Flask for serving the webpage and pygal for creating the graphs. In this tutorial, I will show you how to do that too, but without the database logic. Instead, we’ll get weather data from the Weather Underground and graph that. Let’s get started!

Continue reading Using pyGal Graphs in Flask

eBook Review: Flask Framework Cookbook

Packt Publishing recently sent me a copy of the eBook version of Flask Framework Cookbook by Shalabh Aggarwal. I didn’t read it in its entirety as Cookbooks don’t usually make for a very interesting linear read. I just went through it and cherry picked various recipes. But before I get into too much detail, let’s do the quick review!

Quick Review

  • Why I picked it up: I was asked by the publisher to read the book.
  • Why I finished it: As already mentioned, I actually just skimmed the book and read random recipes
  • Iā€™d give it to: Someone who is new to Flask or possibly an intermediate Flask developer

Continue reading eBook Review: Flask Framework Cookbook

Using Python to Log Data to Loggly

One of my readers suggested that I should try logging my data to a web service called Loggly. As I understand it, Loggly is a way to share log data with everyone in a business so that you no longer need to log in to individual machines. They also provide graphs, filters and searches of the logs. They don’t have a Python API, but it’s still pretty easy to send data to Loggly via Pythons urllib2 module and simplejson. Also note that you can use Loggly for 30-day trial period.

Continue reading Using Python to Log Data to Loggly

Python 101: How to send SMS/MMS with Twilio

I’ve been hearing some buzz about a newish web service called Twilio which allows you to send SMS and MMS messages among other things. There’s a handy Python wrapper to their REST API as well. If you sign up with Twilio, they will give you a trial account without even requiring you to provide a credit card, which I appreciated. You will receive a Twilio number that you can use for sending out your messages. Since you are using a trail account, you do have to authorize any phone numbers you want to send messages to before you can actually send a message. Let’s spend some time learning how this works!

Continue reading Python 101: How to send SMS/MMS with Twilio

A new Python Kickstarter Project: Advanced Web Development, featuring Django 1.6

Last night I received an email about a new Python-related Kickstarter. The Real Python crew added a new author to write a book entirely about Django 1.6. This is a subject that I keep meaning to get into and haven’t had the opportunity to do so. Hopefully by backing this project, I’ll finally learn Django.

I have been impressed with the quality of their previous projects, so I feel that I can safely endorse these authors. I’m sure the project will be of high quality and well worth your time and money. Plus it’s fun to support these guys who want to share their knowledge. If you’re interested in supporting the project you can go to the following address:

Note: They are already fully funded at this point and some of the support levels are already full, so if you want to get in early, now is the time!

Python 101: How to Grab Data from RottenTomatoes

Today we’ll be looking at how to acquire data from the popular movie site, Rotten Tomatoes. To follow along, you’ll want to sign up for an API key here. When you get your key, make a note of your usage limit, if there is one. You don’t want to do too many calls to their API or you may get your key revoked. Finally, it’s always a very good idea to read the documentation of the API you will be using. Here are a couple of links:

Once you’ve perused that or decided that you’ll save it for later, we’ll continue our journey. Continue reading Python 101: How to Grab Data from RottenTomatoes

Bottle – Adding SQLAlchemy to the Todo List Web App

In this article we will be taking the code from the previous article on Bottle and changing it such that it uses SQLAlchemy instead of just normal SQLite code. This will require you to download the bottle-sqlalchemy package from PyPI. You can also install it using “pip install bottle-sqlalchemy”, assuming you have pip installed. You will also need Bottle itself, of course. Once you’re ready, we can continue. Continue reading Bottle – Adding SQLAlchemy to the Todo List Web App

Bottle – Creating a Python Todo List Web App

Python has lots of web frameworks. Bottle is one of them and is considered a WSGI Framework. It’s also sometimes called a “micro-framework”, probably because Bottle consists of just one Python file and has no dependencies besides Python itself. I’ve been trying to learn it and I was using the official Todo-list tutorial on their website. In this article, we’re going to go over this application and improve the UI a little bit. Then in a separate follow-up article, we’ll change the application to use SQLAlchemy instead of straight sqlite. You will probably want to go install Bottle if you’d like to follow along. Continue reading Bottle – Creating a Python Todo List Web App