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 platform
import sqlite3 import sqlite3
import time import time
from urllib.parse import unquote
from typing import Dict, Any, List from typing import Dict, Any, List
from urllib.parse import urlparse, parse_qs 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) active_tab_url = get_active_url_from_accessTree(env, config)
if not isinstance(active_tab_url, str): if not isinstance(active_tab_url, str):
logger.error("active_tab_url is not a string")
return None return None
host = env.vm_ip host = env.vm_ip
port = 9222 # fixme: this port is hard-coded, need to be changed from config file 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 context in browser.contexts:
for page in context.pages: for page in context.pages:
page.wait_for_load_state("networkidle") 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 target_page = page
print("tartget page url: ", target_page.url) print("\33[32mtartget page url: ", target_page.url, "\33[0m")
print("tartget page title: ", target_page.title()) print("\33[32mtartget page title: ", target_page.title(), "\33[0m")
break break
if target_page is None: if target_page is None:
logger.error("Your tab is not the target tab.")
return {} return {}
return_json = {} return_json = {}
if config["category"] == "class": if config["category"] == "class":

View File

@@ -62,8 +62,8 @@
"type": "rule", "type": "rule",
"rules":{ "rules":{
"expected": { "expected": {
"locationName": "Zurich Airport", "locationName": "Zürich",
"dropLocationName": "Zurich Airport", "dropLocationName": "Zürich",
"filterCriteria_carCategory": "large", "filterCriteria_carCategory": "large",
"filterCriteria_sortBy": "PRICE" "filterCriteria_sortBy": "PRICE"
} }

View File

@@ -54,7 +54,7 @@
"rules":{ "rules":{
"expected": { "expected": {
"q": "drip coffee maker", "q": "drip coffee maker",
"tbs": "mr:1,price:1,ppr_min:25,ppr_max:60,pdtr0:1825161|1825162" "tbs": "mr:1,price:1,ppr_min:25,ppr_max:60,sales:1,pdtr0:1825161|1825162"
} }
} }
} }