Web


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! (more…)

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!

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! (more…)

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. (more…)

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! (more…)

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. (more…)

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! (more…)

Last Thursday (the 5th) I attended Pyowa, the local Iowa Python Users group I founded a few years ago. We had Scott Peterson from Principal Financial Group come and talk to us about Library Gadget, a cool Django-based website he created to track what library books his family has checked out. Now he has lots of users using his website. It not only tracks the books you have borrowed, but it’ll auto-renew them if it can and let you know if you’re books are overdue.

He spent most of his time talking about the backend stuff behind the website though. Such as why he chose Amazon Web Services, how he uses Puppet, Vagrant and Fabric to manage his server’s settings and back them up.

The second talk was done by myself and I spoke on my MediaLocker project, an open source wxPython application that is supposed to help you track your media library. Most of my time was spent telling the story behind the project and showing a demo. Then I took some questions.

Overall, I’d say that we had a really good meeting with 10 people showing up. Next month, on February 2nd, we’re bringing in the BIG guns though. We have Doug Hellman and Steve Holden scheduled to Skype in and talk to us.

Doug Hellman is the author of The Python Standard Library By Example, is a senior developer with Racemi, Inc., and communications director of the Python Software Foundation. He has programmed with Python since version 1.4, and has worked on multiple platforms in mapping, medical publishing, banking, and data center automation. Hellmann was previously columnist and editor-in-chief for Python Magazine and, since 2007, has blogged the popular Python Module of the Week

Steve Holden is chairman of the Python Software Foundation and author of Python Web Programming. He owns Python consulting business and does Python training.

TurboGears is one of several web frameworks for Python that are available. The most popular by far is Django. Where I work, we chose TurboGears because of its integration with SQLAlchemy which supports composite keys. At that time, Django did not support that feature and I am not sure if it does yet. Anyway, I develop almost exclusively on a Windows box and have found the TurboGears’ documentation on the subject a little confusing. So here’s how I do it.

Note: We’ll be using TurboGears 2.1 in this tutorial (more…)

As PyCon approaches, the blogger community was invited to interview the speakers that are coming to the event. I chose Wesley Chun, writer of Core Python Programming and co-author of Python Web Development with Django. In this interview, I ask Wesley about his talk, Running Django Apps on Google App Engine and about PyCon in general. Let’s see what he has to say: (more…)

Next Page »