MCPcopy Create free account
hub / github.com/RUC-NLPIR/WebThinker / WebParserClient

Class WebParserClient

scripts/utils/test_webparser.py:5–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3from urllib.parse import urljoin
4
5class WebParserClient:
6 def __init__(self, base_url: str = "http://localhost:8000"):
7 """
8 初始化Web解析器客户端
9
10 Args:
11 base_url: API服务器的基础URL,默认为本地测试服务器
12 """
13 self.base_url = base_url.rstrip('/')
14
15 def parse_urls(self, urls: List[str]) -> List[Dict[str, Union[str, bool]]]:
16 """
17 发送URL列表到解析服务器并获取解析结果
18
19 Args:
20 urls: 需要解析的URL列表
21
22 Returns:
23 解析结果列表
24
25 Raises:
26 requests.exceptions.RequestException: 当API请求失败时
27 """
28 endpoint = urljoin(self.base_url, "/parse_urls")
29 response = requests.post(endpoint, json={"urls": urls})
30 response.raise_for_status() # 如果响应状态码不是200,抛出异常
31
32 return response.json()["results"]
33
34
35# 使用示例

Callers 1

test_webparser.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected