Skip to content

Commit 378b872

Browse files
committed
try/except selenium
1 parent 36f93db commit 378b872

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

_quarto.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ project:
77
- content/manipulation/04a_webscraping_TP.qmd
88
- content/modelisation/index.qmd
99
- content/visualisation/index.qmd
10-
- content/visualisation/matplotlib.qmd
1110
- content/annexes/evaluation.qmd
1211

1312
profile:

content/getting-started/intro/_pourquoi_python_ia.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Because coding is not just about writing lines of code. It’s about understandi
3333

3434
Working with data is first and foremost an engineering process. Code is not the goal—it’s the tool that supports structured reasoning toward solving real-world problems. Just like an engineer designs a bridge to meet a practical need, a data scientist begins with an operational goal—such as building a recommendation system, evaluating the impact of a product launch, or forecasting sales—and reformulates it into an analytical task. This means translating scientific or business ideas into a set of questions, then breaking those down into logical steps, each of which can be executed by a computer.
3535

36-
In this context, an LLM can act as a valuable assistant—but only when the problem is well formulated. If the task is vague or ill-defined, the model’s answers will be approximate or even useless. On standard problems, the results may appear accurate. But for more specific, non-standard tasks, it often becomes necessary to iterate, refine the prompt, reframe the problem… and sometimes still fail to get a satisfactory result. Not because the model is poor, but because good problem formulation—the essence of problem engineering—makes all the difference[^ai-enstein].
36+
In this context, an LLM can act as a valuable assistant—but only when the problem is well formulated. If the task is vague or ill-defined, the model’s answers will be approximate or even useless. On standard problems, the results may appear accurate. But for more specific, non-standard tasks, it often becomes necessary to iterate, refine the prompt, reframe the problem… and sometimes still fail to get a satisfactory result. Not because the model is poor, but because good problem formulation—the essence of problem engineering—makes all the difference[^ai-enstein-en].
3737

38-
[^ai-enstein]: On this topic, see Thomas Wolf’s blog post [_The Einstein AI model_](https://thomwolf.io/blog/scientific-ai.html). Although the post focuses on disruptive innovation and pays less attention to incremental progress, it’s insightful in understanding that LLMs—despite bold predictions from tech influencers—are still just tools. They may excel at standardized tasks, but for now, they remain assistants.
38+
[^ai-enstein-en]: On this topic, see Thomas Wolf’s blog post [_The Einstein AI model_](https://thomwolf.io/blog/scientific-ai.html). Although the post focuses on disruptive innovation and pays less attention to incremental progress, it’s insightful in understanding that LLMs—despite bold predictions from tech influencers—are still just tools. They may excel at standardized tasks, but for now, they remain assistants.
3939

4040
For instance, in the year 2025, [`uv`](https://docs.astral.sh/uv/) saw rapid adoption, as did [`ruff`](https://docs.astral.sh/ruff/) the year before. It will still be some time before generative AIs propose this environment manager on their own, rather than [`poetry`](https://python-poetry.org/). The existence of generative AIs does not, therefore, dispense us, as before, from keeping an active technical watch and being vigilant about changes in practices.
4141
:::

content/manipulation/04a_webscraping_TP.qmd

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,10 +1601,33 @@ have performed the correct action:
16011601
:::
16021602

16031603
```{python}
1604-
#| output: false
1604+
#| eval: false
16051605
png = browser.get_screenshot_as_png()
16061606
```
16071607

1608+
```{python}
1609+
#| output: false
1610+
#| echo: false
1611+
import time
1612+
from selenium.common.exceptions import WebDriverException
1613+
1614+
def get_screenshot_retry(browser, max_retries=3, delay=2):
1615+
for attempt in range(1, max_retries + 1):
1616+
try:
1617+
png = browser.get_screenshot_as_png()
1618+
return png # succès → on sort
1619+
except WebDriverException as e:
1620+
print(f"Échec {attempt}/{max_retries} : {e}")
1621+
if attempt < max_retries:
1622+
time.sleep(delay)
1623+
else:
1624+
raise # après le dernier essai, on relance l’erreur
1625+
1626+
# Utilisation
1627+
png = get_screenshot_retry(browser)
1628+
```
1629+
1630+
16081631
```{python}
16091632
from IPython.display import Image
16101633
Image(png, width='500')

0 commit comments

Comments
 (0)