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

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

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&#39;s just the script that he doesn&#39;t want, I don&#39;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&#39;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&#39;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>



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:

确定