@@ -81,13 +81,15 @@ def getSourceItems(self):
8181 pattern = re .compile (r'/detail/([^/]+)/(\d+)#comment' )
8282
8383 for n in range (1 , pagecount + 1 ):
84+ if n == 1 :
85+ self .waitUncommentableSourceIfNecessary ()
8486 url = 'http://download.csdn.net/my/downloads/%d' % n
8587 html = self .getUrlContent (self .sess , url )
8688 if html is None :
8789 continue
8890 soup = BeautifulSoup (html )
8991 sourcelist = soup .findAll ('a' , attrs = {'class' : 'btn-comment' })
90- if sourcelist is None :
92+ if sourcelist is None or len ( sourcelist ) == 0 :
9193 continue
9294 for source in sourcelist :
9395 href = source .get ('href' , None )
@@ -98,6 +100,22 @@ def getSourceItems(self):
98100
99101 return len (self .sourceitems ) > 0
100102
103+ def waitUncommentableSourceIfNecessary (self ):
104+ """souce cannot comment within 10 minutes after download"""
105+ url = 'http://download.csdn.net/my/downloads/1'
106+ maxMinutes = 11
107+ for i in range (0 , maxMinutes ):
108+ html = self .getUrlContent (self .sess , url )
109+ if html is None :
110+ break
111+ soup = BeautifulSoup (html )
112+ sourcelist = soup .findAll ('span' , attrs = {'class' : 'btn-comment' })
113+ if sourcelist is None or len (sourcelist ) == 0 :
114+ print ('None uncommentable source now!' )
115+ break
116+ print ('Waiting for uncommentable source count down %d minutes.' % (maxMinutes - i ))
117+ time .sleep (60 )
118+
101119 def getPageCount (self ):
102120 """get downloaded resources page count"""
103121 url = 'http://download.csdn.net/my/downloads'
@@ -108,7 +126,7 @@ def getPageCount(self):
108126 soup = BeautifulSoup (html )
109127
110128 pagelist = soup .findAll ('a' , attrs = {'class' : 'pageliststy' })
111- if pagelist is None :
129+ if pagelist is None or len ( pagelist ) == 0 :
112130 return 0
113131
114132 lasthref = pagelist [len (pagelist ) - 1 ].get ('href' , None )
@@ -157,7 +175,7 @@ def getSourceRating(self, sourceid):
157175
158176 soup = BeautifulSoup (html )
159177 ratingspan = soup .findAll ('span' , attrs = {'class' : 'star-yellow' })
160- if ratingspan is None :
178+ if ratingspan is None or len ( ratingspan ) == 0 :
161179 return rating
162180
163181 ratingstyle = ratingspan [0 ].get ('style' , None )
0 commit comments