Prepend feed base url when link is absolute (still not working with relative links tho)
This commit is contained in:
parent
64f6e33b34
commit
6dff57aaaa
@ -67,6 +67,12 @@ def fetch_feed(feed, limit=10):
|
|||||||
author = False
|
author = False
|
||||||
try:
|
try:
|
||||||
link = element.select(feed.link)[0]["href"]
|
link = element.select(feed.link)[0]["href"]
|
||||||
|
if link and len(link) > 2 and link[0] == "/" and link[1] != "/":
|
||||||
|
# fixes issue #5 with relative link
|
||||||
|
# prepend base url
|
||||||
|
base_scheme = feed.url.split("://")[0]
|
||||||
|
base_url = feed.url.split("//")[-1].split("/")[0].split('?')[0]
|
||||||
|
link = base_scheme + "://" + base_url + link
|
||||||
except Exception:
|
except Exception:
|
||||||
link = False
|
link = False
|
||||||
items.append({"title": title, "content": content, "pubDate": date, "author": author, "link": link})
|
items.append({"title": title, "content": content, "pubDate": date, "author": author, "link": link})
|
||||||
|
@ -6,12 +6,14 @@ from django.db.models import ObjectDoesNotExist
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import logging
|
import logging
|
||||||
from urllib.parse import quote_plus, unquote_plus
|
from urllib.parse import quote_plus, unquote_plus
|
||||||
|
import traceback
|
||||||
|
import sys
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def iframe(request, encodedurl):
|
def iframe(request, encodedurl):
|
||||||
|
sys.setrecursionlimit(10000)
|
||||||
try:
|
try:
|
||||||
url = unquote_plus(encodedurl)
|
url = unquote_plus(encodedurl)
|
||||||
req = get_url(url)
|
req = get_url(url)
|
||||||
@ -59,7 +61,7 @@ def iframe(request, encodedurl):
|
|||||||
html = final_html
|
html = final_html
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(e)
|
traceback.print_exc()
|
||||||
return HttpResponse("An error has occured", content_type=500)
|
return HttpResponse("An error has occured", content_type=500)
|
||||||
return HttpResponse(html, content_type=content_type)
|
return HttpResponse(html, content_type=content_type)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user