import urllib import urlparse PARSE_SEARCH_URL = { 'google': 'q', 'yandex': 'text', 'mail': 'q', 'rambler': 'query', 'yahoo': 'p' } def get_search_query(url): u = urlparse.urlparse(url) for search_engine, query_key in PARSE_SEARCH_URL.items(): if not search_engine in u.netloc: continue query = urlparse.parse_qs(u.query).get(query_key) if not query: break if isinstance(query, list): query = query[0] return urllib.unquote(query).decode('utf8')