Fix feeling lucky, fall through to display results if doesn't work

pull/1130/head
David Shen 3 months ago
parent 7a1ebfe975
commit 6f61aa0871
No known key found for this signature in database
GPG Key ID: DDF1B9C8A9AD8CB3

@ -147,8 +147,8 @@ def get_first_link(soup: BeautifulSoup) -> str:
# Replace hrefs with only the intended destination (no "utm" type tags)
for a in soup.find_all('a', href=True):
# Return the first search result URL
if 'url?q=' in a['href']:
return filter_link_args(a['href'])
if a['href'].startswith('http://') or a['href'].startswith('https://'):
return a['href']
return ''

@ -161,10 +161,13 @@ class Search:
if g.user_request.tor_valid:
html_soup.insert(0, bsoup(TOR_BANNER, 'html.parser'))
if self.feeling_lucky:
return get_first_link(html_soup)
else:
formatted_results = content_filter.clean(html_soup)
if self.feeling_lucky:
if lucky_link := get_first_link(formatted_results):
return lucky_link
# Fall through to regular search if unable to find link
self.feeling_lucky = False
# Append user config to all search links, if available
param_str = ''.join('&{}={}'.format(k, v)

Loading…
Cancel
Save