Szyk Cech
unread,Apr 4, 2019, 9:29:42 AM4/4/19You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Witam
Podam pełną wersję mojej funkcji do osadzania całego obrazka w kodzie
html. Skrypt wykrywa normalny odnośnik do obrazka i go wymienia na ciało
kodowane w Base64. Oto kod:
def gEmbedImages(aPage):
lResult = aPage
lRe =
re.compile(r"""<img\s+src\s*=\s*\"(.+?)"\s+alt\s*=\s*"(.+?)"/>""",
re.IGNORECASE)
lMatch = lRe.search(aPage)
while lMatch:
if not os.path.isfile(lMatch.group(1)):
raise Exception("File not found! File:
{0}".format(lMatch.group(1)))
f = open(lMatch.group(1), 'rb')
#lBase64 = """<img alt="{1}"
src=”data:image/png;base64,{0}"/>""".format(base64.b64encode(f.read()).decode('ascii').replace('\n',
''), lMatch.group(2))
lBase64 = """<img alt="%s" src="data:image/png;base64,%s"/>""" %
(lMatch.group(2),
base64.b64encode(f.read()).decode('ascii').replace('\n', ''))
lResult = lResult.replace(lMatch.group(0), lBase64)
lMatch = lRe.search(aPage, lMatch.end())
return lResult
Moje pytanie jest takie:
Dlaczego linia:
#lBase64 = """<img alt="{1}"
src=”data:image/png;base64,{0}"/>""".format(base64.b64encode(f.read()).decode('ascii').replace('\n',
''), lMatch.group(2))
nie działa (błędnie koduje)?
A linia:
lBase64 = """<img alt="%s" src="data:image/png;base64,%s"/>""" %
(lMatch.group(2),
base64.b64encode(f.read()).decode('ascii').replace('\n', ''))
działa bez zarzutu?!?
dzięki i pozdro
Szyk Cech