我正在从以前请求的url获取数据。到目前为止一切正常
我的问题是: 我尝试每X秒进行一次查询,如果查询显示不同的值,则应该执行一些操作。但即使在最终响应返回时也会打印解决捕获!=未准备好
responseback = requests.get('https://2captcha.com/res.php?json=1&action=get&key=' + apikey + "&id=" + finalrequest)
responseback_json = responseback.json()
finalresponseback = responseback_json['request']
print(responseback_json)
notready = (str("CAPCHA_NOT_READY"))
while(finalresponseback == notready):
print("Solving-Capture...")
if finalresponseback != notready:
print("Entering...")
这是因为你写代码的方式, 假设最终回复尚未准备就绪,则会发生以下情况:
但是,如果突然发生变化:
此代码不好,因为如果它更改为not be notready(未准备就绪),则它将退出循环而不执行任何操作,除非它在循环中更改,否则更好的版本是:
上面的代码直接检查循环中的finalresponseback,因此,它将能够打印语句,而不是像以前一样在开始时完全退出
最后,我们可以添加:
每x秒请求一次的代码,如下所示:
最后,是优化代码的技巧,而不是
你能行
这是因为它已经是一个字符串值(由语音标记“”指示)
相关问题 更多 >
编程相关推荐