mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-06 21:11:37 +08:00
refactoring of code and documentation
This commit is contained in:
parent
203ee2c186
commit
b115f9612f
@ -13,8 +13,38 @@ from ..nodes import (
|
||||
|
||||
class CSVScraperGraph(AbstractGraph):
|
||||
"""
|
||||
SmartScraper is a comprehensive web scraping tool that automates the process of extracting
|
||||
information from web pages using a natural language model to interpret and answer prompts.
|
||||
A class representing a graph for extracting information from CSV files.
|
||||
|
||||
Attributes:
|
||||
prompt (str): The prompt used to generate an answer.
|
||||
source (str): The source of the data, which can be either a CSV
|
||||
file or a directory containing multiple CSV files.
|
||||
config (dict): Additional configuration parameters needed by some nodes in the graph.
|
||||
|
||||
Methods:
|
||||
__init__ (prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None):
|
||||
Initializes the CSVScraperGraph with a prompt, source, and configuration.
|
||||
|
||||
__init__ initializes the CSVScraperGraph class. It requires the user's prompt as input,
|
||||
along with the source of the data (which can be either a single CSV file or a directory
|
||||
containing multiple CSV files), and any necessary configuration parameters.
|
||||
|
||||
Methods:
|
||||
_create_graph (): Creates the graph of nodes representing the workflow for web scraping.
|
||||
|
||||
_create_graph generates the web scraping process workflow
|
||||
represented by a directed acyclic graph.
|
||||
This method is used internally to create the scraping pipeline
|
||||
without having to execute it immediately. The result is a BaseGraph instance
|
||||
containing nodes that fetch and process data from a source, and other helper functions.
|
||||
|
||||
Methods:
|
||||
run () -> str: Executes the web scraping process and returns
|
||||
the answer to the prompt as a string.
|
||||
run runs the CSVScraperGraph class to extract information from a CSV file based
|
||||
on the user's prompt. It requires no additional arguments since all necessary data
|
||||
is stored within the class instance. The method fetches the relevant chunks of text or speech,
|
||||
generates an answer based on these chunks, and returns this answer as a string.
|
||||
"""
|
||||
|
||||
def __init__(self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None):
|
||||
|
||||
@ -41,7 +41,8 @@ class PdfScraperMultiGraph(AbstractGraph):
|
||||
>>> result = search_graph.run()
|
||||
"""
|
||||
|
||||
def __init__(self, prompt: str, source: List[str], config: dict, schema: Optional[BaseModel] = None):
|
||||
def __init__(self, prompt: str, source: List[str],
|
||||
config: dict, schema: Optional[BaseModel] = None):
|
||||
|
||||
if all(isinstance(value, str) for value in config.values()):
|
||||
self.copy_config = copy(config)
|
||||
|
||||
@ -43,7 +43,8 @@ class XMLScraperMultiGraph(AbstractGraph):
|
||||
>>> result = search_graph.run()
|
||||
"""
|
||||
|
||||
def __init__(self, prompt: str, source: List[str], config: dict, schema: Optional[BaseModel] = None):
|
||||
def __init__(self, prompt: str, source: List[str],
|
||||
config: dict, schema: Optional[BaseModel] = None):
|
||||
|
||||
if all(isinstance(value, str) for value in config.values()):
|
||||
self.copy_config = copy(config)
|
||||
|
||||
@ -188,4 +188,4 @@ def capture_function_usage(call_fn: Callable) -> Callable:
|
||||
log_event("function_usage", {"function_name": function_name})
|
||||
except Exception as e:
|
||||
logger.debug(f"Failed to send telemetry for function usage. Encountered: {e}")
|
||||
return wrapped_fn
|
||||
return wrapped_fn
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
"""
|
||||
Module for minimizing the code
|
||||
"""
|
||||
from urllib.parse import urljoin
|
||||
from bs4 import BeautifulSoup
|
||||
from minify_html import minify
|
||||
from urllib.parse import urljoin
|
||||
|
||||
def cleanup_html(html_content: str, base_url: str) -> str:
|
||||
"""
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
"""
|
||||
convert_to_md modul
|
||||
convert_to_md module
|
||||
"""
|
||||
from urllib.parse import urlparse
|
||||
import html2text
|
||||
|
||||
Loading…
Reference in New Issue
Block a user