Ongebruikte stukjes code...

Soms schrijf je een mooi stukje code dat precies op het moment dat het af is al weer overbodig is… Dit keer is Google de boosdoener. Er bestaat geen API voor Google Scholar dus ik dacht zelf de HTML output van een search-query dan maar te parsen maar na enkele queries werd m'n IP adres al geblokkeerd en moest ik een Captcha invoeren… Hierbij de code, hopelijk komt 't iemand nog van pas.

void *citationsLoaderThreadedFunction(void *arg) {
 
    for (;;) {
 
        if (datamine.currentStop) {
            TiXmlNode *cur = datamine.currentStop;
            int i=0;
            do {
                string author = datamine.getAuthor(cur); //"Joanne Drinan");
                string title = datamine.getTitle(cur); //"the drinking water handbook");
                int numCitations = datamine.getCitations(cur); 
 
                if (datamine.getCitations(cur)==-1) {
 
                    string url = "http://scholar.google.nl/scholar?as_q="+urlencode(title)+"&as_sauthors="+urlencode(author)+"&num=1&btnG=Zoeken+in+Scholar&as_epq=&as_oq=&as_eq=&as_occt=any&as_publication=&as_ylo=&as_yhi=&hl=nl";
 
                    UrlLoader loader;
                    string result = loader.load(url);
 
                    string qStart = "Geciteerd door ";
                    string qEnd = "<";
 
                    int posStart = result.find(qStart);
                    if (posStart!=string::npos) {
                        result = result.substr(posStart+qStart.size());
                        int posEnd = result.find(qEnd);
                        if (posEnd!=string::npos) {
                            result = result.substr(0,posEnd);
 
                            int citations = toInt(result);
                            datamine.setCitations(cur,citations);
                            cout << "found " << citations << " citations for article " << title << " by " << author << endl;
                        } else {
                            //not found
                            cout << "not found: " << result << endl;
                            datamine.setCitations(cur,0);
                        }
                    } else {
                        //not found
                        cout << "not found: " << result << endl;
                        datamine.setCitations(cur,0);
                    }
 
                    sleep(1);
                }
 
                //next
                if (cur->NextSibling()) cur = cur->NextSibling();
                else cur = datamine.stops->FirstChild("srw:records")->FirstChild("srw:record");
 
 
            } while (cur->NextSibling());
 
        }
 
        sleep(5);
    }
}