无法在 except Exception as e 之后使用 driver.execute_script()

huangapple go评论98阅读模式
英文:

Can't driver.execute_script() after a except Exception as e

问题

  1. 我有一个循环和循环之前的try块,所以在循环之后我添加了以下代码:
  2. ```python
  3. except Exception as e:
  4. print(f"在页面 {page} 上发生错误:{str(e)}")
  5. driver.quit()
  6. time.sleep(1)
  7. driver = webdriver.Chrome(service=service, options=options)
  8. driver.get("https://fr.ereferer.com/")
  9. driver.execute_script(ScriptSiCrashLogin)

但我遇到了一个错误。

我尝试将代码直接放在异常处理块中,它起作用了,只是脚本不起作用,我不明白因为它们是完全相同的代码。

有什么想法来解决这个问题?

  1. <details>
  2. <summary>英文:</summary>
  3. 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)

  1. But I get an error
  2. I tried putting the code in raw in the exception and it worked, it&#39;s just the script that he doesn&#39;t want, I don&#39;t understand as they are the exact same code.
  3. Any idea to solve this?
  4. </details>
  5. # 答案1
  6. **得分**: 0
  7. 我没有解决脚本的问题,我只是找到了另一种方法。
  8. 我想要的是一个无限循环,直到我的代码抓取了所有东西。
  9. 所以我没有使用脚本的东西,我改变了方法,在我的循环之前添加了 `while True :`
  10. 在我的循环后,我在异常处理中添加了访问页面的方法,然后是 `continue`,它重新启动了我的循环。
  11. <details>
  12. <summary>英文:</summary>
  13. Ok I didn&#39;t solve the script problem, I just found another way.
  14. What I wanted was an infinit loop until my code scraped everything.
  15. So I didn&#39;t use the script thing, I changed method and added `while True :`
  16. 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.
  17. </details>

huangapple
  • 本文由 发表于 2023年6月22日 17:50:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定