Tuesday, June 17, 2008

simple C++ program to download what you seached from google

how to compile:

g++ -pipe -Wall -W -g test.c -o test -lptypes



source code:

#include
#include

USING_PTYPES

int main(int argc, char **argv)
{
char buf[256];
ipstream stream("www.google.com", 80);

try
{
stream.open();

// seach "parallel programming" on www.google.com

sprintf(buf, "GET /search?q=%s&num=10&hl=en&lr=&as_qdr=all&start=0&sa=N HTTP/1.1rn", "parallel+programming");
stream.put(buf);
stream.put("Accept: * /*rn" "Host: www.google.comrn" "Connection: closernrn");
stream.flush();

while (!stream.get_eof())
pout.putline(stream.line());

stream.close();
}
catch(estream* e)
{
perr.putf("Error: %sn", pconst(e->get_message()));
delete e;
}

return 0;
}

from : http://tw.myblog.yahoo.com/wei_jeng/article?mid=28&prev=29&next=1&l=f&fid=6

tw.myblog.yahoo.com/wei_jeng

No comments: