From 6b3aa602ef4f10f20d785eecbafceac9602e1ae5 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Sat, 4 Oct 2014 03:24:38 +0400 Subject: [PATCH] add script embedding --- nevernote.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nevernote.py b/nevernote.py index 13cd4ef..23309c2 100755 --- a/nevernote.py +++ b/nevernote.py @@ -137,8 +137,18 @@ def embed_scripts(page, script_urls, base_url=None): continue print('New script: %s' % url) script_link = ' src="%s"' % url - print(script_link) - page = page.replace(script_link, '') + script_link_idx = page.index(script_link) + script_content = get_text( + complete_url(url, base_url), + content={'application/x-javascript', 'text/javascript'}, + charset=base_char + ) + script_start = page.index('>', script_link_idx) + 1 + script_end = page.index('', script_start) + # add script content to page + page = page[:script_start] + script_content + page[script_end:] + # remove script src link + page = page[:script_link_idx] + page[script_link_idx+len(script_link):] return page