Last active
March 29, 2019 02:57
-
-
Save BobDu/4c27d65f20a7e03f74bbacf077499005 to your computer and use it in GitHub Desktop.
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 | |
html_str = """<html> | |
<head> | |
<meta content="always" name="referrer"> | |
<script> | |
var url = ''; | |
url += 'http://mp.w'; | |
url += 'eixin.qq.co'; | |
url += 'm/profile?s'; | |
url += 'rc=3×t'; | |
url += 'amp=1553764'; | |
url += '489&ver=1&s'; | |
url += 'ignature=2D'; | |
url += 'l4Igba30cup'; | |
url += 'oGJv-9Qx6An'; | |
url += '*RjBWoKYAs3'; | |
url += '7xPk4l4RgHJbZhloLPOEzoXt6deO5Yo0dT0v1ISY*8L-Gd*5M0g=='; | |
url.replace("@", ""); | |
window.location.replace(url) | |
</script> | |
</head> | |
<body></body> | |
</html>""" | |
pattern = r"url \+= '(.*)';" | |
url_list = re.findall(pattern, html_str) | |
print(url_list) | |
url = ''.join(url_list) | |
print(url) | |
pattern_replace = r'url.replace\(\"(.?)\", \"(.?)\"\);' | |
url_replace = re.findall(pattern_replace, html_str)[0] | |
print(url_replace[0], url_replace[1]) | |
url.replace(url_replace[0], url_replace[1]) | |
print(url) |
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 java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class UrlRe { | |
public static void main(String[] args){ | |
String html_str = "<html>\n" + | |
" <head>\n" + | |
" <meta content=\"always\" name=\"referrer\"> \n" + | |
" <script>\n" + | |
" var url = '';\n" + | |
" url += 'http://mp.w';\n" + | |
" url += 'eixin.qq.co';\n" + | |
" url += 'm/profile?s';\n" + | |
" url += 'rc=3×t';\n" + | |
" url += 'amp=1553764';\n" + | |
" url += '489&ver=1&s';\n" + | |
" url += 'ignature=2D';\n" + | |
" url += 'l4Igba30cup';\n" + | |
" url += 'oGJv-9Qx6An';\n" + | |
" url += '*RjBWoKYAs3';\n" + | |
" url += '7xPk4l4RgHJbZhloLPOEzoXt6deO5Yo0dT0v1ISY*8L-Gd*5M0g==';\n" + | |
" url.replace(\"@\", \"\");\n" + | |
" window.location.replace(url)\n" + | |
"</script> \n" + | |
" </head>\n" + | |
" <body></body>\n" + | |
"</html>"; | |
String pattern = "url \\+= '(.*)';"; | |
Pattern r = Pattern.compile(pattern); | |
Matcher m = r.matcher(html_str); | |
StringBuffer sb = new StringBuffer(); | |
while (m.find()) { | |
sb.append(m.group(1)); | |
} | |
String url = sb.toString(); | |
String pattern_replace = "url.replace\\(\"(.?)\", \"(.?)\"\\);"; | |
Pattern r_replace = Pattern.compile(pattern_replace); | |
Matcher m_replace = r_replace.matcher(html_str); | |
if (m_replace.find()) { | |
String replace_old = m_replace.group(1); | |
String replace_new = m_replace.group(2); | |
url = url.replace(replace_old, replace_new); | |
} | |
System.out.println(url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment