File tree 1 file changed +4
-12
lines changed
1 file changed +4
-12
lines changed Original file line number Diff line number Diff line change @@ -100,18 +100,11 @@ async def ascrape_undetected_chromedriver(self, url: str) -> str:
100
100
async def ascrape_playwright (self , url : str ) -> str :
101
101
"""
102
102
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.
109
103
"""
110
104
from playwright .async_api import async_playwright
111
105
from undetected_playwright import Malenia
112
106
113
107
logger .info (f"Starting scraping with { self .backend } ..." )
114
- results = ""
115
108
attempt = 0
116
109
117
110
while attempt < self .RETRY_LIMIT :
@@ -127,16 +120,15 @@ async def ascrape_playwright(self, url: str) -> str:
127
120
await page .wait_for_load_state (self .load_state )
128
121
results = await page .content ()
129
122
logger .info ("Content scraped" )
130
- break
123
+ return results
131
124
except (aiohttp .ClientError , asyncio .TimeoutError , Exception ) as e :
132
125
attempt += 1
133
126
logger .error (f"Attempt { attempt } failed: { e } " )
134
127
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 } ")
136
129
finally :
137
- await browser .close ()
138
-
139
- return results
130
+ if 'browser' in locals ():
131
+ await browser .close ()
140
132
141
133
async def ascrape_with_js_support (self , url : str ) -> str :
142
134
"""
You can’t perform that action at this time.
0 commit comments