scrapegraphai 0.2.7__tar.gz → 0.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/PKG-INFO +1 -1
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/pyproject.toml +1 -1
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/base_graph.py +1 -1
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/helpers/__init__.py +1 -0
- scrapegraphai-0.2.8/scrapegraphai/helpers/robots.py +12 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/__init__.py +1 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/rag_node.py +2 -2
- scrapegraphai-0.2.8/scrapegraphai/nodes/robots_node.py +146 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/LICENSE +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/README.md +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/__init__.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/builders/__init__.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/builders/graph_builder.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/__init__.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/abstract_graph.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/script_creator_graph.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/search_graph.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/smart_scraper_graph.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/graphs/speech_graph.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/helpers/models_tokens.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/helpers/nodes_metadata.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/helpers/schemas.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/__init__.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/azure_openai.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/gemini.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/hugging_face.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/ollama.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/openai.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/openai_itt.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/models/openai_tts.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/base_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/conditional_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/fetch_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/generate_answer_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/generate_scraper_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/get_probable_tags_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/image_to_text_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/parse_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/search_internet_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/nodes/text_to_speech_node.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/__init__.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/convert_to_csv.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/convert_to_json.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/parse_state_keys.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/prettify_exec_info.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/remover.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/research_web.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/save_audio_from_bytes.py +0 -0
- {scrapegraphai-0.2.7 → scrapegraphai-0.2.8}/scrapegraphai/utils/token_calculator.py +0 -0
|
@@ -4,6 +4,7 @@ Module for creating the base graphs
|
|
|
4
4
|
import time
|
|
5
5
|
from langchain_community.callbacks import get_openai_callback
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
class BaseGraph:
|
|
8
9
|
"""
|
|
9
10
|
BaseGraph manages the execution flow of a graph composed of interconnected nodes.
|
|
@@ -81,7 +82,6 @@ class BaseGraph:
|
|
|
81
82
|
|
|
82
83
|
with get_openai_callback() as cb:
|
|
83
84
|
result = current_node.execute(state)
|
|
84
|
-
|
|
85
85
|
node_exec_time = time.time() - curr_time
|
|
86
86
|
total_exec_time += node_exec_time
|
|
87
87
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
Module for mapping the models in ai agents
|
|
4
|
+
"""
|
|
5
|
+
robots_dictionary = {
|
|
6
|
+
"gpt-3.5-turbo": ["GPTBot", "ChatGPT-user"],
|
|
7
|
+
"gpt-4-turbo": ["GPTBot", "ChatGPT-user"],
|
|
8
|
+
"claude": ["Claude-Web", "ClaudeBot"],
|
|
9
|
+
"perplexity": "PerplexityBot",
|
|
10
|
+
"cohere": "cohere-ai",
|
|
11
|
+
"anthropic": "anthropic-ai"
|
|
12
|
+
}
|
|
@@ -9,9 +9,9 @@ from langchain.retrievers.document_compressors import EmbeddingsFilter, Document
|
|
|
9
9
|
from langchain_community.document_transformers import EmbeddingsRedundantFilter
|
|
10
10
|
from langchain_community.embeddings import HuggingFaceHubEmbeddings
|
|
11
11
|
from langchain_community.vectorstores import FAISS
|
|
12
|
+
from langchain_community.embeddings import OllamaEmbeddings
|
|
12
13
|
from langchain_openai import OpenAIEmbeddings, AzureOpenAIEmbeddings
|
|
13
14
|
from ..models import OpenAI, Ollama, AzureOpenAI, HuggingFace
|
|
14
|
-
from langchain_community.embeddings import OllamaEmbeddings
|
|
15
15
|
from .base_node import BaseNode
|
|
16
16
|
|
|
17
17
|
|
|
@@ -97,7 +97,7 @@ class RAGNode(BaseNode):
|
|
|
97
97
|
# remove streaming and temperature
|
|
98
98
|
params.pop("streaming", None)
|
|
99
99
|
params.pop("temperature", None)
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
embeddings = OllamaEmbeddings(**params)
|
|
102
102
|
elif isinstance(embedding_model, HuggingFace):
|
|
103
103
|
embeddings = HuggingFaceHubEmbeddings(model=embedding_model.model)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for checking if a website is scrapepable or not
|
|
3
|
+
"""
|
|
4
|
+
from typing import List
|
|
5
|
+
from urllib.parse import urlparse
|
|
6
|
+
from langchain_community.document_loaders import AsyncHtmlLoader
|
|
7
|
+
from langchain.prompts import PromptTemplate
|
|
8
|
+
from langchain.output_parsers import CommaSeparatedListOutputParser
|
|
9
|
+
from .base_node import BaseNode
|
|
10
|
+
from ..helpers import robots_dictionary
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RobotsNode(BaseNode):
|
|
14
|
+
"""
|
|
15
|
+
A node responsible for checking if a website is scrapepable or not.
|
|
16
|
+
It uses the AsyncHtmlLoader for asynchronous
|
|
17
|
+
document loading.
|
|
18
|
+
|
|
19
|
+
This node acts as a starting point in many scraping workflows, preparing the state
|
|
20
|
+
with the necessary HTML content for further processing by subsequent nodes in the graph.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
This node acts as a starting point in many scraping workflows, preparing the state
|
|
24
|
+
with the necessary HTML content for further processing by subsequent nodes in the graph.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
node_name (str): The unique identifier name for the node.
|
|
28
|
+
node_type (str): The type of the node, defaulting to "node". This categorization
|
|
29
|
+
helps in determining the node's role and behavior within the graph.
|
|
30
|
+
The "node" type is used for standard operational nodes.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
node_name (str): The unique identifier name for the node. This name is used to
|
|
34
|
+
reference the node within the graph.
|
|
35
|
+
node_type (str, optional): The type of the node, limited to "node" or
|
|
36
|
+
"conditional_node". Defaults to "node".
|
|
37
|
+
node_config (dict): Configuration parameters for the node.
|
|
38
|
+
force_scraping (bool): A flag indicating whether scraping should be enforced even
|
|
39
|
+
if disallowed by robots.txt. Defaults to True.
|
|
40
|
+
input (str): Input expression defining how to interpret the incoming data.
|
|
41
|
+
output (List[str]): List of output keys where the results will be stored.
|
|
42
|
+
|
|
43
|
+
Methods:
|
|
44
|
+
execute(state): Fetches the HTML content for the URL specified in the state and
|
|
45
|
+
updates the state with this content under the 'document' key.
|
|
46
|
+
The 'url' key must be present in the state for the operation
|
|
47
|
+
to succeed.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, input: str, output: List[str], node_config: dict, force_scraping=True,
|
|
51
|
+
node_name: str = "Robots"):
|
|
52
|
+
"""
|
|
53
|
+
Initializes the RobotsNode with a node name, input/output expressions
|
|
54
|
+
and node configuration.
|
|
55
|
+
|
|
56
|
+
Arguments:
|
|
57
|
+
input (str): Input expression defining how to interpret the incoming data.
|
|
58
|
+
output (List[str]): List of output keys where the results will be stored.
|
|
59
|
+
node_config (dict): Configuration parameters for the node.
|
|
60
|
+
force_scraping (bool): A flag indicating whether scraping should be enforced even
|
|
61
|
+
if disallowed by robots.txt. Defaults to True.
|
|
62
|
+
node_name (str, optional): The unique identifier name for the node.
|
|
63
|
+
Defaults to "Robots".
|
|
64
|
+
"""
|
|
65
|
+
super().__init__(node_name, "node", input, output, 1)
|
|
66
|
+
self.llm_model = node_config["llm"]
|
|
67
|
+
self.force_scraping = force_scraping
|
|
68
|
+
|
|
69
|
+
def execute(self, state):
|
|
70
|
+
"""
|
|
71
|
+
Executes the node's logic to fetch HTML content from a specified URL and
|
|
72
|
+
update the state with this content.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
state (dict): The current state of the graph, expected to contain a 'url' key.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
dict: The updated state with a new 'document' key containing the fetched HTML content.
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
KeyError: If the 'url' key is not found in the state, indicating that the
|
|
82
|
+
necessary information to perform the operation is missing.
|
|
83
|
+
"""
|
|
84
|
+
template = """
|
|
85
|
+
You are a website scraper and you need to scrape a website.
|
|
86
|
+
You need to check if the website allows scraping of the provided path. \n
|
|
87
|
+
You are provided with the robot.txt file of the website and you must reply if it is legit to scrape or not the website
|
|
88
|
+
provided, given the path link and the user agent name. \n
|
|
89
|
+
In the reply just write "yes" or "no". Yes if it possible to scrape, no if it is not. \n
|
|
90
|
+
Ignore all the context sentences that ask you not to extract information from the html code.\n
|
|
91
|
+
Path: {path} \n.
|
|
92
|
+
Agent: {agent} \n
|
|
93
|
+
robots.txt: {context}. \n
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
print(f"--- Executing {self.node_name} Node ---")
|
|
97
|
+
|
|
98
|
+
# Interpret input keys based on the provided input expression
|
|
99
|
+
input_keys = self.get_input_keys(state)
|
|
100
|
+
|
|
101
|
+
# Fetching data from the state based on the input keys
|
|
102
|
+
input_data = [state[key] for key in input_keys]
|
|
103
|
+
|
|
104
|
+
source = input_data[0]
|
|
105
|
+
output_parser = CommaSeparatedListOutputParser()
|
|
106
|
+
if not source.startswith("http"):
|
|
107
|
+
raise ValueError(
|
|
108
|
+
"Operation not allowed")
|
|
109
|
+
|
|
110
|
+
else:
|
|
111
|
+
parsed_url = urlparse(source)
|
|
112
|
+
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}"
|
|
113
|
+
loader = AsyncHtmlLoader(f"{base_url}/robots.txt")
|
|
114
|
+
document = loader.load()
|
|
115
|
+
model = self.llm_model.model_name
|
|
116
|
+
|
|
117
|
+
if "ollama" in model:
|
|
118
|
+
model = model.split("/", maxsplit=1)[-1]
|
|
119
|
+
|
|
120
|
+
try:
|
|
121
|
+
agent = robots_dictionary[model]
|
|
122
|
+
|
|
123
|
+
except KeyError:
|
|
124
|
+
agent = model
|
|
125
|
+
|
|
126
|
+
prompt = PromptTemplate(
|
|
127
|
+
template=template,
|
|
128
|
+
input_variables=["path"],
|
|
129
|
+
partial_variables={"context": document,
|
|
130
|
+
"agent": agent
|
|
131
|
+
},
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
chain = prompt | self.llm_model | output_parser
|
|
135
|
+
is_scrapable = chain.invoke({"path": source})[0]
|
|
136
|
+
print(f"Is the provided URL scrapable? {is_scrapable}")
|
|
137
|
+
if "no" in is_scrapable:
|
|
138
|
+
print("\033[33mScraping this website is not allowed\033[0m")
|
|
139
|
+
if not self.force_scraping:
|
|
140
|
+
raise ValueError(
|
|
141
|
+
'The website you selected is not scrapable')
|
|
142
|
+
else:
|
|
143
|
+
print("\033[92mThe path is scrapable\033[0m")
|
|
144
|
+
|
|
145
|
+
state.update({self.output[0]: is_scrapable})
|
|
146
|
+
return state
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|