Saturday, January 14, 2012

python script to download files via google search

Just now some one was asking to me on chat if there is some script which can download the files if given a google search query.

When thinking I suddenly remember that I had coded such a script some time ago using xgoogle libray of python. So I just searched for my script and here it is.

As you know I am lazy, I have used xgoogle and not directly handle google via httplib or urllib etc etc. My script used getopt library to parse the options given to the script. (again I am lazy)
(xgoogle library can be downloaded at http://www.catonmat.net/blog/python-library-for-google-search/)

The general syntax of this script is

python gsrchDwn.py --query "query_text" [--ftype file_extension] [--cnt contine_result_number] [--dir download_dir]

usage: python gsrchDwn.py --query maths made easy --ftype pdf

IMP Notes
1)It proper results are not got try the query in " (double quotes)
2) This file need xgoogle library found at http://www.catonmat.net/blog/python-library-for-google-search/

If --dir is not given it will download files into current directory.
If the script is stopped inbetween you can continue from the last result number by using --cnt result_number

This time I am have become a good boy and also added a status printing which shows how much percentage of current file is downlaoded.

grsrchDwn.py can be downloaded HERE

Let me know any comments.