1

I am using the xgoogle python library to try to search as specific site. The code works for me when I do not use the "site:" indicator in the keyword search. If I do used it, the result set is empty. Does anyone have any thoughts how to get the code below to work?

from xgoogle.search import GoogleSearch, SearchError

gs = GoogleSearch("site:reddit.com fun")  
gs.results_per_page = 50  
results = gs.get_results()  
print results  
for res in results:  
    print res.title.encode("utf8")  
print  
Nick
  • 159
  • 1
  • 7
  • This may be the reason: [Xgoogle Python library is not working any more](http://stackoverflow.com/questions/7279934/xgoogle-python-library-is-not-working-any-more) – ire_and_curses Sep 24 '12 at 04:49

2 Answers2

1

A simple url with the "q" parameter (e.g. "http://www.google.com/search?&q=site:reddit.com+fun") works, so I assume it's some other problem.

If you are using pkrumins/xgoogle, a quick (and dirty) fix is to modify search.py line 240 as follows:

if not title or not url:

This is because Google changes their SERP layout, which breaks the _extract_description() function.

You can also take a look at this fork.

user748455
  • 385
  • 1
  • 3
  • 10
0

Put keyword before site:XX. It works for me.

haipython
  • 96
  • 2