Last active
November 2, 2015 02:27
-
-
Save MinxianLi/a78caa80d4c3b1c80262 to your computer and use it in GitHub Desktop.
Fetch jpg from a webpage - ONLY WORKS FOR PYTHON 2
This file contains 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
Credit: http://www.rudy-yuan.net/archives/189/ | |
#! /usr/bin/python | |
import re | |
import urllib | |
def getHtml(url): | |
request = urllib.urlopen(url) | |
html = request.read() | |
return html | |
def downImg(html): | |
url_re = r'src="(.+?\.jpg)"' | |
url_re_obj = re.compile(url_re, re.I) | |
img_lists = url_re_obj.findall(html) | |
name_id = 0 | |
for img in img_lists: | |
urllib.urlretrieve(img, "%s.jpg" % name_id) | |
name_id += 1 | |
html = getHtml("http://tieba.baidu.com/p/4103769237") | |
print "begin..." | |
downImg(html) | |
print "finish..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment