def google(query): url = google_search(query + sites_query) if not url: return None match = re.match('(?:https?://)?xkcd.com/(\d+)/?', url) if match: return match.group(1)