From 442060b2ef7ac9104795a82f040e21fa9012fedd Mon Sep 17 00:00:00 2001 From: Don-Swanson <32144818+Don-Swanson@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:12:26 -0500 Subject: [PATCH] Fixed JSON search function to improve link extraction by targeting specific result containers and retrieving all relevant text, enhancing the accuracy of search results. --- app/routes.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/routes.py b/app/routes.py index 24beea3..0dfd31a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -407,15 +407,30 @@ def search(): json_soup = bsoup(str(response), 'html.parser') results = [] seen = set() - for a in json_soup.find_all('a', href=True): - href = a['href'] - if not href.startswith('http'): + + # Find all result containers (using known result classes) + result_divs = json_soup.find_all('div', class_=['ZINbbc', 'ezO2md']) + + for div in result_divs: + # Find the first valid link in this result container + link = None + for a in div.find_all('a', href=True): + if a['href'].startswith('http'): + link = a + break + + if not link: continue + + href = link['href'] if href in seen: continue - text = a.get_text(strip=True) + + # Get all text from the result container, not just the link + text = div.get_text(separator=' ', strip=True) if not text: continue + seen.add(href) results.append({'href': href, 'text': text})