diff --git a/cookbook/helper/recipe_html_import.py b/cookbook/helper/recipe_html_import.py index 469ebd220..f8ce33273 100644 --- a/cookbook/helper/recipe_html_import.py +++ b/cookbook/helper/recipe_html_import.py @@ -73,11 +73,9 @@ def get_recipe_from_source(text, url, space): html_data = [] images = [] + # text = normalize_string(text) try: parse_list.append(remove_graph(json.loads(text))) - if not url and 'url' in parse_list[0]: - url = parse_list[0]['url'] - scrape = text_scraper("", url=url) except JSONDecodeError: soup = BeautifulSoup(text, "html.parser") @@ -85,8 +83,6 @@ def get_recipe_from_source(text, url, space): images += get_images_from_source(soup, url) for el in soup.find_all('script', type='application/ld+json'): el = remove_graph(el) - if not url and 'url' in el: - url = el['url'] if type(el) == list: for le in el: parse_list.append(le) @@ -99,6 +95,15 @@ def get_recipe_from_source(text, url, space): parse_list.append(le) elif type(el) == dict: parse_list.append(el) + + # if a url was not provided, try to find one in the first document + if not url and len(parse_list) > 0: + if 'url' in parse_list[0]: + url = parse_list[0]['url'] + + if type(text) == dict: + scrape = text_scraper("", url=url) + elif type(text) == str: scrape = text_scraper(text, url=url) recipe_json = helper.get_from_scraper(scrape, space) diff --git a/cookbook/helper/scrapers/scrapers.py b/cookbook/helper/scrapers/scrapers.py index 5e2262abe..decf81642 100644 --- a/cookbook/helper/scrapers/scrapers.py +++ b/cookbook/helper/scrapers/scrapers.py @@ -30,7 +30,7 @@ def text_scraper(text, url=None): url=None ): self.wild_mode = False - self.exception_handling = None + self.exception_handling = _exception_handling self.meta_http_equiv = False self.soup = BeautifulSoup(page_data, "html.parser") self.url = url diff --git a/cookbook/static/js/bookmarklet.js b/cookbook/static/js/bookmarklet.js index 156ba1ce2..4d0892ad3 100644 --- a/cookbook/static/js/bookmarklet.js +++ b/cookbook/static/js/bookmarklet.js @@ -44,4 +44,4 @@ } )(); } -})(); +})(); \ No newline at end of file diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html index 0c4222490..6ea418756 100644 --- a/cookbook/templates/url_import.html +++ b/cookbook/templates/url_import.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load i18n %} {% load static %} +{% load custom_tags %} {% block title %}{% trans 'URL Import' %}{% endblock %} @@ -22,7 +23,14 @@ {% block content %}
-

{% trans 'Import' %}

+
+

{% trans 'Import' %}

+ + {% trans 'Bookmark Me!' %} +