-1
我得到了for循環的代碼,它工作得很好。不過,我在while循環中苦苦掙扎。它看起來像我得到空json objects.How我可以得到「while」工作,銘記在某些時候json對象變成{「data」:[],「result」:「ok」}隨着while循環通過與scrapy的ajax
我while循環
def after_login(self,response):
if "smg" in response.body:
#for i in range(0,100,10):
minime = 2
i = 10
while len(self.parse_firstcall(response)['data']) > 1 or minime > 1:
print('------------------------------------')
print(len(self.parse_firstcall(response)['data']))
print(str(minime))
print(str(i))
print('-------------------------------------')
yield FormRequest(
url='URL',
formdata={'act': 'serial', 'type': 'search', 'o': str(i), 's': '3','t': '0'},
callback=self.parse_firstcall
)
minime = 0
i += 10
time.sleep(5)
def parse_firstcall(self,response):
try:
firstc = response.body
self.serialj = json.loads(firstc)
except:
self.serialj = {"data":['why', 'always', 'me'], "result": "ok"}
return self.serialj