英文:
Can't driver.execute_script() after a except Exception as e
问题
我有一个循环和循环之前的try块,所以在循环之后我添加了以下代码:
```python
except Exception as e:
print(f"在页面 {page} 上发生错误:{str(e)}")
driver.quit()
time.sleep(1)
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://fr.ereferer.com/")
driver.execute_script(ScriptSiCrashLogin)
但我遇到了一个错误。
我尝试将代码直接放在异常处理块中,它起作用了,只是脚本不起作用,我不明白因为它们是完全相同的代码。
有什么想法来解决这个问题?
<details>
<summary>英文:</summary>
I have a loop and a try before it, so after the loop I added
except Exception as e:
print(f"Il y a eu une erreur sur la page {page}: {str(e)}")
driver.quit()
time.sleep(1)
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://fr.ereferer.com/")
driver.execute_script(ScriptSiCrashLogin)
But I get an error
I tried putting the code in raw in the exception and it worked, it's just the script that he doesn't want, I don't understand as they are the exact same code.
Any idea to solve this?
</details>
# 答案1
**得分**: 0
我没有解决脚本的问题,我只是找到了另一种方法。
我想要的是一个无限循环,直到我的代码抓取了所有东西。
所以我没有使用脚本的东西,我改变了方法,在我的循环之前添加了 `while True :`
在我的循环后,我在异常处理中添加了访问页面的方法,然后是 `continue`,它重新启动了我的循环。
<details>
<summary>英文:</summary>
Ok I didn't solve the script problem, I just found another way.
What I wanted was an infinit loop until my code scraped everything.
So I didn't use the script thing, I changed method and added `while True :`
before my loops, in the except after my loop I added the way to get to the page and after this `continue` which restart my loop.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论