web_extractor.py 607 B

12345678910111213141516
  1. from typing import Union
  2. from qwen_agent.tools.base import BaseTool, register_tool
  3. from qwen_agent.tools.simple_doc_parser import SimpleDocParser
  4. @register_tool('web_extractor')
  5. class WebExtractor(BaseTool):
  6. description = '根据网页URL,获取网页内容的工具'
  7. parameters = [{'name': 'url', 'type': 'string', 'description': '网页URL', 'required': True}]
  8. def call(self, params: Union[str, dict], **kwargs) -> str:
  9. params = self._verify_json_format_args(params)
  10. url = params['url']
  11. parsed_web = SimpleDocParser().call({'url': url})
  12. return parsed_web