Skip to content

Commit 12f2808

Browse files
committed
Fix none reference img
Signed-off-by: Shawn Hsu <ambersun1019.shawn@gmail.com>
1 parent 514ba8a commit 12f2808

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/core/image_checker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ def check_page(self, page_url: str) -> (list, bool):
1313

1414
page_fail_results = []
1515
try:
16+
current_image = None
17+
1618
page = self.context.new_page()
1719
cdp_session = page.context.new_cdp_session(page)
1820
cdp_session.send("Network.setCacheDisabled", {"cacheDisabled": True})
1921

2022
try:
2123
response = page.goto(page_url, wait_until="load", timeout=90000)
2224
except Exception:
23-
logger.debug(f"Timeout loading {page_url}, skipping")
25+
logger.warning(f"Timeout loading {page_url}, skipping")
2426
raise
2527

2628
if not response or response.status != 200:
@@ -70,6 +72,7 @@ def check_page(self, page_url: str) -> (list, bool):
7072

7173
images = page.locator("img").all()
7274
for index, img in enumerate(images):
75+
current_image = img
7376
width, height = self._check_image(img, page_url)
7477
logger.debug(
7578
f"Checking image",
@@ -92,7 +95,7 @@ def check_page(self, page_url: str) -> (list, bool):
9295
page_fail_results.append(
9396
{
9497
"page_url": page_url,
95-
"image_url": img.get_attribute("src"),
98+
"image_url": "unknown" if current_image is None else current_image.get_attribute("src"),
9699
}
97100
)
98101
finally:

0 commit comments

Comments
 (0)