Last active
August 29, 2015 13:57
-
-
Save bongkook/9447005 to your computer and use it in GitHub Desktop.
Only image files with the HTML parsing and extraction
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
# -*- coding: utf-8 -*- | |
import re, sys | |
def extractimgs(html): | |
exp = re.compile(r'<img.+?src="(http://imgcomic\.naver\.net/webtoon/[0-9]+/[0-9]+/(.+?\.(jpg|png|gif)))".*?>') | |
imgs = exp.findall(html) | |
return imgs | |
def main(argv): | |
if len(argv) != 2: | |
print 'Usage: extractimgs.py <filename>' | |
return 1 | |
f = open(argv[1], 'r') | |
html = f.read() | |
f.close() | |
imgs = extractimgs(html) | |
if len(imgs) == 0: | |
print >> sys.stderr, "No images!" | |
return 1 | |
for img in imgs: | |
print img[0] # full link | |
print img[1] # file name | |
print img[2] # extension | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment