Does Pygoogle allows for advanced search options?

N

neocortex

Hello All,
Can anyone help me with the Pygoogle:
from pygoogle import pygoogle
word = u'something'
request_word = word.encode('utf-8')
request = ('%s+site:.edu' % request_word)
g = pygoogle(request)
g.get_result_count()

Now, I realized that domain restriction works (site:.edu etc.), but I
would like to be able to control for language too. Is that possible
with the Pygoogle? If not, how can I make that happen?

Thanks!
PM
 
C

Chris Rebert

Hello All,
Can anyone help me with the Pygoogle:
from pygoogle import pygoogle

You're apparently talking about http://code.google.com/p/pygoogle/
rather than http://pygoogle.sourceforge.net/ ; the former appears to
have "borrowed" the latter's name without permission. Oi!
word = u'something'
request_word = word.encode('utf-8')
request = ('%s+site:.edu' % request_word)
g = pygoogle(request)
g.get_result_count()

Now, I realized that domain restriction works (site:.edu etc.), but I
would like to be able to control for language too. Is that possible
with the Pygoogle? If not, how can I make that happen?

The library doesn't seem to have built-in support for filtering by
language (and Google lacks a search query-string-based operator for
that), but it looks like you could implement that feature by adding an
"lr" parameter with an appropriate value to the query `args`
dictionary. See the "lr?" entry under "Web Search Specific Arguments"
on http://code.google.com/apis/websearch/docs/reference.html , and
lines 68 & 102 of pygoogle.py.

Cheers,
Chris
 
N

neocortex

The library doesn't seem to have built-in support for filtering by
language (and Google lacks a search query-string-based operator for
that), but it looks like you could implement that feature by adding an
"lr" parameter with an appropriate value to the query `args`
dictionary. See the "lr?" entry under "Web Search Specific Arguments"
onhttp://code.google.com/apis/websearch/docs/reference.html, and
lines 68 & 102 of pygoogle.py.

From those lines, it can be concluded that lr=lang_?? is not
supported, unfortunately. And, when I execute, I get an error.
Is there any other way to get Google search from Python? I really need
only number of hits.

Best,
PM
 
C

Chris Rebert

From those lines, it can be concluded that lr=lang_?? is not
supported, unfortunately.

Right; that's why I said "you could implement that feature". Pretty
easily it would seem.
And, when I execute, I get an error.

What exactly are you executing, and what's the exact error? Vagueness
is the enemy of debugging.

Regards,
Chris
 
P

Petar Milin

Right; that's why I said "you could implement that feature". Pretty
easily it would seem.
Thanks for believing in me ( ;-) ), but I am a newbie in Python world,
although with some experience in other prog. languages.
So, if I read pygoogle.py well, I sould add lr parameter in init and
then after lines 68 and 102?

Thanks again! You guys here are very kind and helpful!
Best,
Petar
 
S

Stefan Sonnenberg-Carstens

Am 21.11.2010 11:01, schrieb Petar Milin:
Thanks for believing in me ( ;-) ), but I am a newbie in Python world,
although with some experience in other prog. languages.
So, if I read pygoogle.py well, I sould add lr parameter in init and
then after lines 68 and 102?
Correct.
I just did not read source code enough to realize the parameter is needed
twice. You just could hack that out, too :)
Normally (what is normal, anyway ?) it's good practice to create an
contructor (__init__) in python which has the most common options
as keyword arguments and default values assigned, like so:

class Foo:
def __init__(self,lr='lang_en',url='http://some.of.this'):
self.lr = lr
self.url = url
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top