feat: add json multiscraper

This commit is contained in:
Marco Vinciguerra 2024-06-01 12:04:19 +02:00
parent 4d42d7bfc6
commit 5bda918a39
5 changed files with 15 additions and 24 deletions

View File

@ -2,7 +2,8 @@
Module for showing how PDFScraper multi works
"""
import os
from scrapegraphai.graphs import PdfScraperMultiGraph
import json
from scrapegraphai.graphs import JSONScraperMultiGraph
graph_config = {
"llm": {
@ -25,23 +26,14 @@ file_path = os.path.join(curr_dir, FILE_NAME)
with open(file_path, 'r', encoding="utf-8") as file:
text = file.read()
json_scraper_graph = JSONScraperGraph(
prompt="List me all the authors, title and genres of the books",
source=text, # Pass the content of the file, not the file object
sources = [text, text]
multiple_search_graph = JSONScraperMultiGraph(
prompt= "List me all the authors, title and genres of the books",
source= sources,
schema=None,
config=graph_config
)
results = []
for source in sources:
pdf_scraper_graph = PdfScraperMultiGraph(
prompt=prompt,
source=source,
config=graph_config
)
result = pdf_scraper_graph.run()
results.append(result)
print(results)
result = multiple_search_graph.run()
print(json.dumps(result, indent=4))

View File

@ -16,7 +16,6 @@ graph_config = {
"temperature": 0,
},
"verbose": True,
"headless": False,
}
# Covert to list

View File

@ -17,4 +17,4 @@ from .omni_scraper_graph import OmniScraperGraph
from .omni_search_graph import OmniSearchGraph
from .smart_scraper_multi_graph import SmartScraperMultiGraph
from .pdf_scraper_multi import PdfScraperMultiGraph
from .json_scraper_multi import JsonScraperMultiGraph
from .json_scraper_multi import JSONScraperMultiGraph

View File

@ -1,5 +1,5 @@
"""
JsonScraperMultiGraph Module
JSONScraperMultiGraph Module
"""
from copy import copy, deepcopy
@ -15,9 +15,9 @@ from ..nodes import (
)
class JsonScraperMultiGraph(AbstractGraph):
class JSONScraperMultiGraph(AbstractGraph):
"""
JsonScraperMultiGraph is a scraping pipeline that scrapes a list of URLs and generates answers to a given prompt.
JSONScraperMultiGraph is a scraping pipeline that scrapes a list of URLs and generates answers to a given prompt.
It only requires a user prompt and a list of URLs.
Attributes:

View File

@ -19,4 +19,4 @@ from .generate_answer_csv_node import GenerateAnswerCSVNode
from .generate_answer_pdf_node import GenerateAnswerPDFNode
from .graph_iterator_node import GraphIteratorNode
from .merge_answers_node import MergeAnswersNode
from .generate_answer_omni_node import GenerateAnswerOmniNode
from .generate_answer_omni_node import GenerateAnswerOmniNode