#! /usr/bin/python
# -*- coding:utf-8 -*-
import time
import re
import http
import tools
import urllib
import urllib2
import os
from socket import error as SocketError
class START:
def __init__(self):
self.URL = 'http://super-search.u.qiniudn.com/';
# 开启网络请求
def requestOpener(self, url):
try:
opener = urllib2.build_opener(urllib2.HTTPHandler())
opener.addheaders = [('User_Agent',
'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1')]
response = opener.open(url, timeout=20)
return 'isExits'
except urllib2.HTTPError, e:
print e.code
return ''
except urllib2.URLError, e:
print e.reason
return ''
except SocketError, e:
# print 'SocketError: ' + str(e.errno)
return ''
def writeFile(self, sort):
try:
with open('./file/sort.txt', 'ab+') as f:
f.write(str(sort)+'\n')
except Exception, e:
print 'Exception: ' + str(e)
def testPage(self, sort):
result = self.requestOpener(self.URL + str(sort) + "_magazineThumbnail.jpg")
if result == '':
print str(sort) + " No"
else:
print str(sort) + ' Yes'
self.writeFile(sort)
def testSort(self):
fromID = 1
endID = 101
while True:
if fromID > endID:
break
self.testPage(fromID)
fromID+=1
print 'a';
if __name__ == '__main__':
t1 = time.time()
START().testSort()
t2 = time.time() - t1
print '总共用时:' + str(t2)