Skip to content

Instantly share code, notes, and snippets.

@MinxianLi
Last active November 2, 2015 02:27
Show Gist options
  • Save MinxianLi/a78caa80d4c3b1c80262 to your computer and use it in GitHub Desktop.
Save MinxianLi/a78caa80d4c3b1c80262 to your computer and use it in GitHub Desktop.
Fetch jpg from a webpage - ONLY WORKS FOR PYTHON 2
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