Skip to content

Instantly share code, notes, and snippets.

@fxxkscript
Created July 24, 2012 13:54
Show Gist options
  • Save fxxkscript/3170013 to your computer and use it in GitHub Desktop.
Save fxxkscript/3170013 to your computer and use it in GitHub Desktop.
China Jiliang University fashmash
# -*- coding: utf-8 -*-
# China Jiliang University fashmash
import urllib2
import webbrowser
import os
import time
opener = urllib2.build_opener()
opener.addheaders.append(('Cookie', 'ASP.NET_SessionId=2afhjqjxa0qy0tutkwojab55'))
def get_image(id):
try:
response = opener.open('http://210.33.40.130/readimagexs.aspx?xh='+id)
except urllib2.URLError, e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
else:
content = response.read()
length = content.find('<!DOCTYPE')
content = content[0:length]
if len(content) > 5:
image = open('images/'+id+'.jpg', 'wb')
image.write(content)
image.close()
response.close()
return True
else:
opener.close()
response.close()
return False
if __name__=='__main__':
for secondary_college in range(20,999):
temp_id = '08%03d01101' % (secondary_college)
if get_image(temp_id):
for profession in range(1,12):
for classroom in range(1,5):
for student_id in range(1,40):
id = '08%03d%02d%1d%02d' % (secondary_college, profession, classroom, student_id)
if not os.path.isfile('images/'+id+'.jpg'):
if get_image(id):
print 'download '+id+' success'
time.sleep(0.1)
else:
print id+' no such user'
time.sleep(0.1)
break
else:
print id+' aleady exists'
time.sleep(0.1)
else:
print 'no such %03d secondary_college' % secondary_college
print '--EOF--Thank you!'
# -*- coding: utf-8 -*-
# China Jiliang University fashmash
import urllib2
import webbrowser
import os
import time
opener = urllib2.build_opener()
opener.addheaders.append(('Cookie', 'ASP.NET_SessionId=2afhjqjxa0qy0tutkwojab55'))
def get_image(id):
try:
response = opener.open('http://210.33.40.130/readimagexs.aspx?xh='+id)
except urllib2.URLError, e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
else:
content = response.read()
length = content.find('<!DOCTYPE')
content = content[0:length]
if len(content) > 5:
image = open('images/'+id+'.jpg', 'wb')
image.write(content)
image.close()
response.close()
return True
else:
opener.close()
response.close()
return False
if __name__=='__main__':
for secondary_college in range(1,9):
for profession in range(1,99):
temp_id = '0830%01d%02d110' % (secondary_college, profession)
if get_image(temp_id):
for classroom in range(1,10):
for student_id in range(1,40):
id = '0830%01d%02d%1d%02d' % (secondary_college, profession, classroom, student_id)
if not os.path.isfile('images/'+id+'.jpg'):
if get_image(id):
print 'download '+id+' success'
time.sleep(0.1)
else:
print id+' no such user'
time.sleep(0.1)
break
else:
print id+' aleady exists'
time.sleep(0.1)
else:
print temp_id + ' not exists'
print '--EOF--Thank you!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment