From 340e41d33935ae49b292ae098e4b187602d5850c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Thu, 14 Feb 2019 16:55:04 +0100 Subject: [PATCH] Handle inexact matches on cheese.com --- services/cheesecom.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/cheesecom.py b/services/cheesecom.py index d1c2b4f..12354a3 100644 --- a/services/cheesecom.py +++ b/services/cheesecom.py @@ -16,11 +16,13 @@ class CheeseCom(object): def query(self, q): try: r = requests.get(BASE_URL, params=dict(q=q)) - if not r.history: - raise CheeseComError('no exact match') d = pq(r.content) + if not r.history: + url = d('div[class~="cheese-item"]').eq(0).find('a').eq(0).attr('href') + r = requests.get(BASE_URL + url) + d = pq(r.content) summary = [] - for p in d('ul[class="summary-points"]').find('p').items(): + for p in d('ul[class~="summary-points"]').find('p').items(): summary.append(html.unescape(p.html(method='text'))) return dict( url=d('meta[name="twitter:url"]').attr('content'),