Skip to content

Commit c84ff56

Browse files
authored
Merge pull request #826 from ScrapeGraphAI/fix-runtime-error
fix: error on fetching the code
2 parents b98dd39 + 7285ab0 commit c84ff56

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

scrapegraphai/docloaders/chromium.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,11 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
100100
async def ascrape_playwright(self, url: str) -> str:
101101
"""
102102
Asynchronously scrape the content of a given URL using Playwright's async API.
103-
104-
Args:
105-
url (str): The URL to scrape.
106-
107-
Returns:
108-
str: The scraped HTML content or an error message if an exception occurs.
109103
"""
110104
from playwright.async_api import async_playwright
111105
from undetected_playwright import Malenia
112106

113107
logger.info(f"Starting scraping with {self.backend}...")
114-
results = ""
115108
attempt = 0
116109

117110
while attempt < self.RETRY_LIMIT:
@@ -127,16 +120,15 @@ async def ascrape_playwright(self, url: str) -> str:
127120
await page.wait_for_load_state(self.load_state)
128121
results = await page.content()
129122
logger.info("Content scraped")
130-
break
123+
return results
131124
except (aiohttp.ClientError, asyncio.TimeoutError, Exception) as e:
132125
attempt += 1
133126
logger.error(f"Attempt {attempt} failed: {e}")
134127
if attempt == self.RETRY_LIMIT:
135-
results = f"Error: Network error after {self.RETRY_LIMIT} attempts - {e}"
128+
raise RuntimeError(f"Failed to fetch {url} after {self.RETRY_LIMIT} attempts: {e}")
136129
finally:
137-
await browser.close()
138-
139-
return results
130+
if 'browser' in locals():
131+
await browser.close()
140132

141133
async def ascrape_with_js_support(self, url: str) -> str:
142134
"""

0 commit comments

Comments
 (0)