我有一只正常工作的蜘蛛,但有时会抛出一个错误。当它发生时,我希望它从头开始重新启动脚本。
我已经使用while
循环进行了测试,但蜘蛛并不是为它设计的。我可以使用if
语句捕获错误,如下所示:
if response.status == error code:
#here I want it do restart the script from the beginning
else:
#continue scraping
我试过os.execv(__file__,sys.argv)
,但我没有运气。