Pickle Problem

Fab86 fabien.hall at gmail.com
Tue Mar 3 13:39:43 EST 2009


On Mar 3, 1:54 pm, Fab86 <fabien.h... at gmail.com> wrote:
> On Mar 3, 1:02 pm, MRAB <goo... at mrabarnett.plus.com> wrote:
>
>
>
> > Fab86 wrote:
> > > I am getting res1 and res2 etc from this code:
>
> > > srch1 = WebSearch(app_id=YahooKey)
> > > srch1.query = "avoir site:.al"
> > > res1 = srch1.parse_results()
>
> > > srch2 = WebSearch(app_id=YahooKey)
> > > srch2.query = "avoir site:.fr"
> > > res2 = srch2.parse_results()
>
> > > After identifying res1, I then use the total_results_available class
> > > which saves res1 as an integer.
>
> > > This is happening 200 times.
>
> > > How could I make a for loop to do this?
>
> > langs = ["al", "fr"]
> > for lang in langs:
> >      srch = WebSearch(app_id=YahooKey)
> >      srch.query = "avoir site:.%s" % lang
> >      res = srch.parse_results()
> >      print >> f, res.total_results_available
>
> > You might be able to move the "WebSearch" line out of the loop.
>
> > Anyway, have you read through a tutorial?
>
> thanks for this, works perfectly just as I wanted it to.
>
> Again, thanks to everyone who has helped me.
>
> Fabien

I am having a bit on an issue getting my program to work. The online
database which I am trying to contact keep timing out meaning I can
not carry out my 200 searches without being interupted.

I believe that the solution would be to include an exception handler
with a timer delay if this error occurs so wait a bit then carry on
however having spent hours looking at this I can not get my head
around how to do such a thing.

I am running with this code:

f = open('TestRun1.txt', 'w')
domains = ["nf", "se", "au", "ca", "nl", "be", "is", "us", "jp", "ie",
"ch", "uk", "fi", "at", "lu", "fr", "dk", "nc", "de", "es", "it",
"il", "hk", "gr", "sg", "pt", "si", "mk", "bb", "cy", "mt", "cz",
"bn", "ar", "sc", "ee", "pl", "hu", "sh", "bh", "lt", "sk", "cl",
"kw", "cr", "uy", "qa", "hr", "ae", "lv", "bs", "cu", "mx", "tt",
"aq", "bg", "ru", "ly", "my", "mo", "pa", "by", "to", "mu", "al",
"ba", "sr", "ve", "ro", "ua", "lc", "br", "co", "om", "ws", "th",
"sa", "kz", "jm", "lb", "fj", "am", "ph", "mv", "pe", "tm", "vc",
"tr", "py", "jo", "az", "tn", "gr", "cl", "dm", "lk", "ge", "do",
"bz", "ec", "im", "ps", "sv", "gy", "cv", "sy", "uz", "dz", "gq",
"kg", "id", "vn", "md", "bo", "hn", "tj", "mm", "ni", "za", "eg",
"gp", "ga", "st", "sb", "ma", "na", "in", "bw", "vu", "kh", "gh",
"mm", "pg", "bt", "la", "km", "sz", "bd", "sd", "np", "cm", "pk",
"tg", "cd", "ls", "ug", "zw", "ke", "ye", "mg", "ng", "mr", "ht",
"dj", "gm", "er", "sn", "tl", "rw", "gn", "bj", "tz", "ci", "zm",
"mw", "ao", "td", "cd", "cf", "et", "mz", "gw", "bi", "ml", "bf",
"ne", "sl", "af", "ad", "ck", "kp", "gl", "va", "ir", "ki", "lr",
"li", "mh", "fm", "mc", "nr", "nu", "pw", "pr", "sm", "rs", "so",
"tw", "tv", "eh"]
srch = WebSearch(app_id=YahooKey)
for domain in domains:
     srch.query = "avoir site:.%s" % domain
     res = srch.parse_results()
     print >> f, res.total_results_available


f.close()

Any help would be greatly appreciated.

Fabien



More information about the Python-list mailing list