import rdflib, urllib2 from BeautifulSoup import BeautifulSoup def openidcheck(url, s): global ts d = BeautifulSoup(urllib2.urlopen(url)) delegates = d.findAll("link", {"rel": "openid.delegate"}) if len(delegates) is not 0: ts.add((rdflib.URIRef(s), rdflib.URIRef("http://xmlns.com/foaf/0.1/openid"), rdflib.URIRef(url))) for i in delegates: ts.add((rdflib.URIRef(s), rdflib.URIRef("http://xmlns.com/foaf/0.1/openid"), rdflib.URIRef(str(i['href'])))) ts = rdflib.ConjunctiveGraph() ts.parse("http://tommorris.org/foaf", "xml") hplist = ts.query("SELECT DISTINCT ?s ?url WHERE { ?s . ?s ?url . }") wllist = ts.query("SELECT DISTINCT ?s ?url WHERE { ?s . ?s ?url . }") for s, url in hplist: openidcheck(str(url), str(s)) for s, url in wllist: openidcheck(str(url), str(s)) print ts.serialize()