|
1 | 1 | from typing import Union, List, TYPE_CHECKING |
2 | | -from playwright.sync_api import FrameLocator, ElementHandle |
| 2 | +from playwright.sync_api import FrameLocator, ElementHandle, Error |
3 | 3 | from bs4 import BeautifulSoup |
4 | 4 | from loguru import logger |
5 | 5 | from dendrite.sync_api._core._type_spec import PlaywrightPage |
@@ -34,19 +34,19 @@ def expand_iframes( |
34 | 34 | new_iframe_path = f"{new_iframe_path}{iframe_id}" |
35 | 35 | try: |
36 | 36 | content_frame = iframe.content_frame() |
37 | | - except Exception as e: |
| 37 | + if content_frame is None: |
| 38 | + continue |
| 39 | + content_frame.evaluate( |
| 40 | + GENERATE_DENDRITE_IDS_IFRAME_SCRIPT, {"frame_path": new_iframe_path} |
| 41 | + ) |
| 42 | + frame_content = content_frame.content() |
| 43 | + frame_tree = BeautifulSoup(frame_content, "html.parser") |
| 44 | + mild_strip_in_place(frame_tree) |
| 45 | + merge_iframe_to_page(iframe_id, page_soup, frame_tree) |
| 46 | + expand_iframes(page, page_soup, new_iframe_path, iframe) |
| 47 | + except Error as e: |
38 | 48 | logger.debug(f"Error getting content frame for iframe {iframe_id}: {e}") |
39 | 49 | continue |
40 | | - if content_frame is None: |
41 | | - continue |
42 | | - content_frame.evaluate( |
43 | | - GENERATE_DENDRITE_IDS_IFRAME_SCRIPT, {"frame_path": new_iframe_path} |
44 | | - ) |
45 | | - frame_content = content_frame.content() |
46 | | - frame_tree = BeautifulSoup(frame_content, "html.parser") |
47 | | - mild_strip_in_place(frame_tree) |
48 | | - merge_iframe_to_page(iframe_id, page_soup, frame_tree) |
49 | | - expand_iframes(page, page_soup, new_iframe_path, iframe) |
50 | 50 |
|
51 | 51 |
|
52 | 52 | def merge_iframe_to_page(iframe_id: str, page: BeautifulSoup, iframe: BeautifulSoup): |
|
0 commit comments