fix the error caused by url encoding

This commit is contained in:
Jason Lee
2024-02-27 18:37:32 +08:00
parent 0edbcf404d
commit 2c08a02206
3 changed files with 10 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import os
import platform
import sqlite3
import time
from urllib.parse import unquote
from typing import Dict, Any, List
from urllib.parse import urlparse, parse_qs
@@ -985,6 +986,7 @@ def get_active_tab_html_parse(env, config: Dict[str, Any]):
"""
active_tab_url = get_active_url_from_accessTree(env, config)
if not isinstance(active_tab_url, str):
logger.error("active_tab_url is not a string")
return None
host = env.vm_ip
port = 9222 # fixme: this port is hard-coded, need to be changed from config file
@@ -1017,12 +1019,14 @@ def get_active_tab_html_parse(env, config: Dict[str, Any]):
for context in browser.contexts:
for page in context.pages:
page.wait_for_load_state("networkidle")
if page.url == active_tab_url:
# the accTree and playwright can get encoding(percent-encoding) characters, we need to convert them to normal characters
if unquote(page.url) == unquote(active_tab_url):
target_page = page
print("tartget page url: ", target_page.url)
print("tartget page title: ", target_page.title())
print("\33[32mtartget page url: ", target_page.url, "\33[0m")
print("\33[32mtartget page title: ", target_page.title(), "\33[0m")
break
if target_page is None:
logger.error("Your tab is not the target tab.")
return {}
return_json = {}
if config["category"] == "class":