Jump to content

How to extract base64 image string from html using python?


Recommended Posts

here i have and html code which contains an a base64 image code and if i want to get image from  html which is in form of base64 code so first i have to extract that code  to decode the image from base64 code.

here is html i have :

<div class="captcha-image" style="background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAA1AN4DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD15VXYPlHT0p2xf7o/KojcwRtHFJNGkjj5UZgC30HepqbuhKxh+IrLUbmCE6ZIyMjHeqPsLZxjnjpz+dX9Ltp7fTYIrx/MuFHzsTnv69/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KKUaOWAOvY45H0NezsoYc1SuNPimHzKKkZ4donhAQaksoV22n5d3avaNFtTb2qqR2p0OjwxPuCCtJECLgUAPrnPGNzcQ6YkUUYMMpIlYjOMYIH4/0ro6juPN+zS+Rjzth8vPTdjj9a1ozUKik1exFSPNFoyPC9glnpEcnlNHNP8ANJu6nBOPwxz+NbdcboOq3drqctvq9zIm8fKs+c78jGPQYz7V2VaYqEo1W5a3JoyThZdAooormNQqne6ZZ6kyi7hEmwfL8xGM9ehq5XM+I9eutOlSO1VVO8qzOuc4VTx/33+lbUITnO1N2ZFSUYxvLY6NVGwdenqa43+3tR/4Sf7J9o/0f7X5WzaPu7sdetFFdOChGXPzK+hjXbXLY7TaPf8AM1zereIZtP1qOzjgRozt3FmOTn09P1oorPBQjUqNSV9Cq8nGN0dJtHv+Zo2j3/M0UVyG5xXiC+u4PEaxRSoANnllolYpn0JGevNdrtHv+ZooruxSSp07djno/HL1DaPf8zRtHv8AmaKK4ToMTxTeT2GlLJbPtd5QhJG7ggk8HjtUPhErcabJO8USyiUoXjjCEjAPOAPWiiu+yWDv1uc1/wB/byOh2j3/ADNG0e/5miiuA6Q2j3/M1Rt9ItLa6NxHGgb+ECNF2fQhQf1ooqlKSTSYnFMvbR7/AJmjaPf8zRRUjDaPf8zRtHv+ZoooANo9/wAzRtHv+ZoooAyb3Q1vL9bjzY1U43o1ujlsf7RGR+ta20e/5miirlUlJJPoSopaoNo9/wAzRtHv+ZooqCg2j3/M15vr+oXN1qNxbzOGihmZYxtGVAOOvWiivSy1JzbZyYt2irH/2Q==')"></div>

and i want to get the base64 image code from html 

base64 image code :

/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy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4Sf7J9o/0f7X5WzaPu7sdetFFdOChGXPzK+hjXbXLY7TaPf8AM1zereIZtP1qOzjgRozt3FmOTn09P1oorPBQjUqNSV9Cq8nGN0dJtHv+Zo2j3/M0UVyG5xXiC+u4PEaxRSoANnllolYpn0JGevNdrtHv+ZooruxSSp07djno/HL1DaPf8zRtHv8AmaKK4ToMTxTeT2GlLJbPtd5QhJG7ggk8HjtUPhErcabJO8USyiUoXjjCEjAPOAPWiiu+yWDv1uc1/wB/byOh2j3/ADNG0e/5miiuA6Q2j3/M1Rt9ItLa6NxHGgb+ECNF2fQhQf1ooqlKSTSYnFMvbR7/AJmjaPf8zRRUjDaPf8zRtHv+ZoooANo9/wAzRtHv+ZoooAyb3Q1vL9bjzY1U43o1ujlsf7RGR+ta20e/5miirlUlJJPoSopaoNo9/wAzRtHv+ZooqCg2j3/M15vr+oXN1qNxbzOGihmZYxtGVAOOvWiivSy1JzbZyYt2irH/2Q==

how can i extract this base64 image code.

help!!

thanks in advance

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...