Close this search box.

The XFN microformat and a spider in Python

One microformat which is one of the more used ones is XFN. XFN stands for XHTML Friends Network and is about marking links to the pages of your contacts and friends. Additionally you can use XFN to mark links to your own pages (e.g. linking all your profiles together).

Doing that is quite easy, you simply add a HTML attribute rel="me" to the link-tag, e.g.

<a href="" rel="me">my flickr pages</a>

If I have this on my profile page it says that I this flickr URL is also one of my pages. That way some spider can collect all the information about me. In my case I prepared a page on my site which can serve as a starting point for such a spider, linking to many of my profiles.

But what if somebody else links with rel=“me“ to one of my pages?

In this case it helps to check for symmetrical relationships. This means that the page I link to should also link the same way back.

What about different URLs pointing to the same page

Apparently URLs can be written differently and if it’s just omitting the „www.“ or having a trailing slash. This can be a problem for identifying your profiles. One way to avoid this problem is to canonicalizing the link addresses, like Google’s Social Graph API does.

The problem for websites might be still to find out what links are the same as it always means spidering the web which might be hard if you don’t have a link page like I have. Google of course has a better position here as they have all pages already indexed and finding out those links is then more or less asking the own database. That’s what Google’s Social Graph API can do for.

It’s also about friends

XFN is not only about your web sites but also about who your friends are. The same mechnism is used but instead of „me“ other names are used, some can also be mixed, e.g.

<a href="" rel="friend met colleague">...

This means, the person you link to is your friend, you met in real life and it’s a colleague. A more general way of simply linking to contacts is using the „contact“ name. This is what e.g. Twitter does in it’s contact list. Here is an example with the hCard microformat mixed in:

 <span class="vcard">    <a href=""        class="url" rel="contact" title="Scobleizer"><img 			alt="Scobleizer" 			class="photo fn" id="profile-image"                         src="...." height="24" width="24"></a>  </span>

In this case the rel=“contact“ is the XFN part, the other bold parts belong to the hCard microformat.

Of course you need to crawl the web here to really retrieve all your contacts and also find out which friends links are actually pointing to the same person. Thus you probably also need to follow all the me-Links for every friend. Otherwise you cannot know that


are the same person unless there is some Link-Graph with me-Links which links these together (e.g. by starting from my connect-Page).

Thus using XFN is probably only useful if you want to write spiders. It also might mean that you cannot display information in real-time as spidering might take some time. Alternatively you can of course use the Google API.

A XFN Spider in Python (actually 2)

A while back I created a Python script which retrieves rel=me links starting from one page. It does no canonicalization and only outputs a list. But it should be easy to extend. There is one script I wrote initially and another one which does the same job but uses Linden Lab’s eventlet library for retrieving links in a non-blocking, more concurrent way.

You can find both scripts at the Google Code project I created:

Both scripts need the HTML parser BeautifulSoup to be installed and the eventlet apparently needs eventlet to be installed (I used the SVN version).

Both scripts are called with a starting URL, optionally you can add -v if you want verbose output on what it does.

Here is an example output:

44 profiles found Takashi
Wir lieben Web!

Here it’s also interesting to see how they get more and more although I haven’t added more services myself. But it means that more and more services actually add those links (like flickr).

Technorati Tags: , , , , ,

Teile diesen Beitrag