This commit is contained in:
@@ -895,57 +895,6 @@ async def capture_outgoing_calls_service(decoded_url):
|
||||
|
||||
# Perform the operation
|
||||
return await safe_browser_operation(decoded_url, outgoing_calls_operation)
|
||||
|
||||
async def fetch_json_service(decoded_url):
|
||||
"""Service function to fetch JSON content from a website"""
|
||||
print(f"Fetching JSON from: {decoded_url}")
|
||||
|
||||
# Define the operation to perform with the browser
|
||||
async def json_operation(page):
|
||||
try:
|
||||
response = await page.goto(decoded_url, wait_until='networkidle', timeout=30000)
|
||||
if not response:
|
||||
print(f"Warning: No response object returned for {decoded_url}")
|
||||
|
||||
# Get the final URL after any redirects and decode it
|
||||
final_url = page.url
|
||||
decoded_final_url = unquote(final_url)
|
||||
|
||||
# Try to get JSON content
|
||||
try:
|
||||
content = await page.content()
|
||||
# Check if the page contains JSON
|
||||
if content.strip().startswith('{') or content.strip().startswith('['):
|
||||
return {
|
||||
"status": "success",
|
||||
"url": decoded_url,
|
||||
"final_url": decoded_final_url,
|
||||
"content": content,
|
||||
"content_type": "json"
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"status": "success",
|
||||
"url": decoded_url,
|
||||
"final_url": decoded_final_url,
|
||||
"content": content,
|
||||
"content_type": "html"
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "partial",
|
||||
"url": decoded_url,
|
||||
"final_url": decoded_final_url,
|
||||
"error": f"Could not get content: {str(e)}"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error during JSON fetch: {e}")
|
||||
return {"status": "error", "url": decoded_url, "error": str(e)}
|
||||
|
||||
# Perform the operation
|
||||
return await safe_browser_operation(decoded_url, json_operation)
|
||||
|
||||
async def get_resulting_url_service(decoded_url):
|
||||
"""Service function to get the resulting URL after navigation (handles redirects)"""
|
||||
print(f"Getting resulting URL for: {decoded_url}")
|
||||
|
||||
Reference in New Issue
Block a user