Category Archives: Web

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

Python 101 – Intro to XML Parsing with ElementTree

If you have followed this blog for a while, you may remember that we’ve covered several XML parsing libraries that are included with Python. In this article, we’ll be continuing that series by taking a quick look at the ElementTree library. You will learn how to create an XML file, edit XML and parse the XML. For comparison’s sake, we’ll use the same XML we used in the previous minidom article to illustrate the differences between using minidom and ElementTree. Here is the original XML:

<?xml version="1.0" ?>
<zappointments reminder="15">
    <appointment>
        <begin>1181251680</begin>        
        <uid>040000008200E000</uid>
        <alarmtime>1181572063</alarmtime>
        <state></state>
        <location></location>
        <duration>1800</duration>
        <subject>Bring pizza home</subject>
    </appointment>
</zappointments>

Now let’s dig into the Python! Continue reading Python 101 – Intro to XML Parsing with ElementTree

A Preview of the New Python.org Website

The Python.org website is finally getting a much needed update and at PyCon 2013, they announced that you can now check out a preview of what it’s going to look like here: http://preview.python.org/

There’s a call for beta testers at the bottom of the website, so if you want to help Python, here’s a really simple way for you to do so. They’re still putting content on the site, so it’s going to be kind of rough for a while with placeholders and what-not, but I like the look and feel already. Go check it out for yourself and see what you think!

Python 101: How to submit a web form

Today we’ll spend some time looking at three different ways to make Python submit a web form. In this case, we will be doing a web search with duckduckgo.com searching on the term “python” and saving the result as an HTML file. We will use Python’s included urllib modules and two 3rd party packages: requests and mechanize. We have three small scripts to cover, so let’s get cracking! Continue reading Python 101: How to submit a web form

Python 101: How to Download a File

Downloading files from the internet is something that almost every programmer will have to do at some point. Python provides several ways to do just that in its standard library. Probably the most popular way to download a file is over HTTP using the urllib or urllib2 module. Python also comes with ftplib for FTP downloads. Finally there’s a new 3rd party module that’s getting a lot of buzz called requests. We’ll be focusing on the two urllib modules and requests for this article. Continue reading Python 101: How to Download a File

Parsing XML with Python using lxml.objectify

A couple years ago I started a series of articles on XML parsing. I covered lxml’s etree and Python’s included minidom XML parsing library. For whatever reason I didn’t notice lxml’s objectify sub-package, but I saw it recently and decided I should check it out. To my mind, the objectify module seems to be even more “Pythonic” than etree is. Let’s take a some time and go over my old XML examples using objectify and see how it’s different! Continue reading Parsing XML with Python using lxml.objectify

Book Review: web2py Application Development Cookbook

I have read about web2py on several occasions, but never used it myself. Then a few weeks ago, a representative from Packt Publishing contacted me about reviewing their new cookbook about web2py. It’s written by seven authors, namely: Richard Gordon, Pablo Martin Mulone, Mariano Reingart, Bruno Cezar Rocha, Massimo Di Pierro, Michele Comitini and Jonathan Lundell. I have to admit that I wondered how you could have a coherent book with so many authors, but since it’s a cookbook, it works out pretty well. Continue reading Book Review: web2py Application Development Cookbook

Website Automation with Python, Firefox and Selenium

An appropriate alternate title would be: How to control a web page or test your website with Python. Recently, I was given the following assignment:

1) Login to a website
2) click on a toolbar and load a specific search form
3) enter some data into one of the fields on the form and search
4) if found, click another button
5) repeat

Of course, I was supposed to do all this with Python, my favorite programming language. My first thought was to use the Mechanize package, but while I could login to the website using that, I was unable to get it to load the form. Why? Well, unfortunately the aforementioned toolbar was made using javascript and it seemed to be generating the form too. For whatever reason, the Python port doesn’t support loading javascript elements, although I did find out that the project it’s based on has a javascript plugin, so there is hope that it might eventually. Thus, I went looking for another solution and recalled that Selenium might fit the bill. In the end, it worked quite well. Since I won’t be able to show you what I did exactly because it was for an internal project, we’ll be automating Gmail instead. Let’s get cracking! Continue reading Website Automation with Python, Firefox and Selenium