add rpc
This commit is contained in:
87
get_rpc_config_auto.py
Normal file
87
get_rpc_config_auto.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import json
|
||||
import time
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
def analyze_gwt_response(response_text):
|
||||
"""Finds potential coordinates to validate response data."""
|
||||
candidates = []
|
||||
try:
|
||||
if response_text.startswith("//OK"):
|
||||
response_text = response_text[4:]
|
||||
data = json.loads(response_text)
|
||||
if isinstance(data, list):
|
||||
for i in range(len(data) - 2):
|
||||
val1 = data[i]
|
||||
val2 = data[i+2]
|
||||
if (isinstance(val1, (int, float)) and isinstance(val2, (int, float))):
|
||||
if abs(val1) > 100000 and abs(val2) > 100000:
|
||||
candidates.append((val1, val2))
|
||||
if len(candidates) > 5: break
|
||||
except:
|
||||
pass
|
||||
return candidates
|
||||
|
||||
def get_fresh_config(map_url):
|
||||
"""
|
||||
Launches headless browser to scrape headers, body, AND cookies.
|
||||
"""
|
||||
print(f"--- Auto-Repair: Launching Browser for {map_url} ---")
|
||||
|
||||
captured_request = None
|
||||
captured_cookies = []
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
# Create a persistent context to ensure cookies are tracked
|
||||
context = browser.new_context()
|
||||
page = context.new_page()
|
||||
|
||||
def handle_request(request):
|
||||
nonlocal captured_request
|
||||
if ".rpc" in request.url and request.method == "POST":
|
||||
try:
|
||||
if "getCombinedOutageDetails" in request.post_data or "getOutages" in request.post_data:
|
||||
captured_request = {
|
||||
'url': request.url,
|
||||
'headers': request.headers,
|
||||
'body': request.post_data
|
||||
}
|
||||
except:
|
||||
pass
|
||||
|
||||
page.on("request", handle_request)
|
||||
|
||||
try:
|
||||
page.goto(map_url, wait_until="networkidle", timeout=45000)
|
||||
time.sleep(5)
|
||||
|
||||
# Capture cookies from the browser context
|
||||
captured_cookies = context.cookies()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Auto-Repair Browser Error: {e}")
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
if captured_request:
|
||||
req_headers = captured_request['headers']
|
||||
# Clean headers (keep specific GWT ones, discard dynamic browser ones that requests handles)
|
||||
clean_headers = {
|
||||
'content-type': req_headers.get('content-type', 'text/x-gwt-rpc; charset=UTF-8'),
|
||||
'x-gwt-module-base': req_headers.get('x-gwt-module-base'),
|
||||
'x-gwt-permutation': req_headers.get('x-gwt-permutation'),
|
||||
'Referer': map_url
|
||||
}
|
||||
|
||||
return {
|
||||
'headers': clean_headers,
|
||||
'body': captured_request['body'],
|
||||
'url': captured_request['url'],
|
||||
'cookies': captured_cookies # <--- Return cookies
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
url = input("Enter Map URL: ")
|
||||
print(get_fresh_config(url))
|
||||
Reference in New Issue
Block a user