Skip to content

Instantly share code, notes, and snippets.

@Answeror
Created September 16, 2012 05:22
Show Gist options
  • Select an option

  • Save Answeror/3731112 to your computer and use it in GitHub Desktop.

Select an option

Save Answeror/3731112 to your computer and use it in GitHub Desktop.
程序员的爱情表白
# fetch jpgs from tuita
import urllib3
from pyquery import PyQuery as pq
http = urllib3.PoolManager()
url = 'http://yokicharlotte.tuita.com/blogpost/23832258'
r = http.request('GET', url)
d = pq(r.data.decode('utf-8'))
imgs = d('.photo_group')('p.pic')('img')
imgs.map(lambda e: pq(this).attr('src'))
srcs = imgs.map(lambda e: pq(this).attr('src'))
for i, src in enumerate(srcs):
print('do %02d' % i)
while True:
r = http.request('GET', src)
if r.status == 200:
break
print('retry')
with open('%02d.jpg' % i, 'wb') as f:
f.write(r.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment