Thread: store plugin
View Single Post
Old 05-15-2011, 08:56 AM   #10
user_none
Sigil & calibre developer
user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.
 
user_none's Avatar
 
Posts: 2,488
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
First you need to use the Browser object. The Browser takes into account the users proxy settings. You can use urllib2 like you are but you will need to handle detecting and using the users proxy settings. It's easier just to use Browser as it does this for you. The Browser also sets the user agent to a Firefox to avoid issues with sites that filter or give different responses to non-browser apps.

The Browser is able to POST data. Here is an example.

Code:
# -*- coding: utf-8 -*-

import urllib
from contextlib import closing

from calibre import browser

url='http://www.gandalf.com.pl/s/'
data = {
    'search': 'Andrzej Franaszek',
    'dzialx': '11'
}

br = browser()

with closing(br.open(url, data=urllib.urlencode(data), timeout=10)) as f:
    print f.read()
As for why it's not showing any results. My guess is it has to do with your generic test values. The search dialog is smart and does additional filtering. Many stores always return results even when they have nothing to do with the users search. So the search dialog filters out all results that don't have anything to do with the query. Meaning if you search for "Franaszek" and the SearchResults objects come back with a title of "Blah" and an author of "Lalala" it will be filtered because "Franaszek" doesn't appear in either field.
user_none is offline   Reply With Quote