Created
October 18, 2017 05:03
-
-
Save Liam0205/330988e166d282b4c24cc028704ed440 to your computer and use it in GitHub Desktop.
re.sub(http -> https)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| pattern = r'(?P<front><img.*?src=\\")(?P<protocol>http://)(?P<url>.*?\\")(?P<back>.*?\/>)' | |
| _replace_protocol = lambda m: \ | |
| '%s%s%s%s' % (m.group('front'), 'https://', m.group('url'), m.group('back')) | |
| source = r'<img src=\"http://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D220/sign=ce3bec3b4d36acaf5de091fe4cd88d03/dc54564e9258d109b60a06b0d758ccbf6d814dc2.jpg\" layout=\"1\" style=\"float:right;\" class=\"fadeInLeftBig\" data-type=\"img\" />' | |
| print source | |
| print re.sub(pattern, _replace_protocol, source) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment