Created
April 27, 2014 08:52
-
-
Save gialloporpora/11340885 to your computer and use it in GitHub Desktop.
Extracts links from a json file
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 | |
def elff(filename): | |
f = open(filename, "r") | |
s=f.read() | |
f.close() | |
regex = re.compile(r'"(http[^"]*)"') | |
links = regex.findall(s) | |
return links | |
def savefile(filename, s): | |
f = open(filename, "w") | |
f.write(s) | |
f.close() | |
if __name__=='__main__': | |
import sys | |
filename = sys.argv[1] | |
if len(sys.argv)==2: ofilename="%s.html" %filename | |
else: ofilename=sys.argv[2] | |
print ofilename | |
links = elff(filename) | |
s = "<ol>" | |
for i in links: | |
s+= '<li><a href="%s" target="_blank">%s</a></li>\n' %(i, i) | |
s+="</ol>" | |
savefile(ofilename, s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment