clean-up working
This commit is contained in:
@@ -20,14 +20,11 @@ def analyze_gwt_response(response_text):
|
||||
return candidates
|
||||
|
||||
def fetch_live_data(map_url):
|
||||
"""
|
||||
Uses a real browser to fetch data AND capture the raw request details.
|
||||
"""
|
||||
print(f"--- Browser Fetch: {map_url} ---")
|
||||
data_result = None
|
||||
captured_headers = None
|
||||
captured_cookies = None
|
||||
captured_body = None # <--- New: Capture raw body
|
||||
captured_body = None
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True, args=['--disable-blink-features=AutomationControlled'])
|
||||
@@ -39,7 +36,7 @@ def fetch_live_data(map_url):
|
||||
def handle_request(request):
|
||||
nonlocal captured_headers, captured_body
|
||||
if ".rpc" in request.url and request.method == "POST":
|
||||
# Capture the request details blindly before we even know if it works
|
||||
# Capture request blindly first
|
||||
if "getCombinedOutageDetails" in request.post_data or "getOutages" in request.post_data:
|
||||
captured_headers = request.headers
|
||||
captured_body = request.post_data
|
||||
@@ -75,15 +72,14 @@ def get_fresh_config(map_url):
|
||||
data, headers, cookies, body = fetch_live_data(map_url)
|
||||
|
||||
if headers and body:
|
||||
# Minimal cleaning: Only remove headers that 'requests' MUST generate itself
|
||||
# This keeps all custom NISC/GWT headers safe.
|
||||
# Minimal Cleaning: Remove headers requests handles automatically
|
||||
forbidden = {'content-length', 'host', 'connection', 'cookie', 'accept-encoding'}
|
||||
clean_headers = {k: v for k, v in headers.items() if k.lower() not in forbidden}
|
||||
|
||||
return {
|
||||
'headers': clean_headers,
|
||||
'body': body, # Save exact body
|
||||
'url': headers.get('url', map_url.replace('.html', '') + '/GWT.rpc'), # Best guess URL if missing
|
||||
'body': body,
|
||||
'url': headers.get('url', map_url.replace('.html', '') + 'GWT.rpc'),
|
||||
'cookies': cookies,
|
||||
'user_agent': headers.get('user-agent')
|
||||
}
|
||||
@@ -93,5 +89,4 @@ if __name__ == "__main__":
|
||||
url = input("Enter Map URL: ")
|
||||
res = get_fresh_config(url)
|
||||
if res:
|
||||
print("Success! Captured Body length:", len(res['body']))
|
||||
print("Captured Headers:", res['headers'].keys())
|
||||
print("Success! Captured new config.")
|
||||
Reference in New Issue
Block a user