Skip to content

Python scraper based on AI

fix(proxy-rotation): removed duplicated arg and passed the loader_kwarhs correctly to the node

Marco Perini1e9a56461632
diff --git a/examples/openai/proxy.py b/examples/openai/proxy.py
new file mode 100644
index 00000000..6572a6e8
--- /dev/null
+++ b/examples/openai/proxy.py
@@ -0,0 +1,11 @@
+from scrapegraphai.utils import search_proxy_servers
+
+proxies = search_proxy_servers(
+ anonymous=True,
+ countryset={"IT"},
+ # secure=True,
+ timeout=1.0,
+ max_shape=2
+)
+
+print(proxies)
\ No newline at end of file
diff --git a/examples/openai/smart_scraper_openai.py b/examples/openai/smart_scraper_openai.py
index 32a1942b..d8adb548 100644
--- a/examples/openai/smart_scraper_openai.py
+++ b/examples/openai/smart_scraper_openai.py
@@ -22,6 +22,19 @@ graph_config = {
"model": "gpt-3.5-turbo",
},
"verbose": True,
+ "headless": False,
+ "loader_kwargs": {
+ "proxy" : {
+ "server": "broker",
+ "criteria": {
+ "anonymous": True,
+ # "secure": True,
+ "countryset": {"IT"},
+ "timeout": 5.0,
+ "max_shape": 2
+ },
+ },
+ }
}
# ************************************************
diff --git a/scrapegraphai/graphs/abstract_graph.py b/scrapegraphai/graphs/abstract_graph.py
index a71508a4..38eab97f 100644
--- a/scrapegraphai/graphs/abstract_graph.py
+++ b/scrapegraphai/graphs/abstract_graph.py
@@ -58,8 +58,11 @@ class AbstractGraph(ABC):
"verbose", False)
self.headless = True if config is None else config.get(
"headless", True)
+ self.loader_kwargs = config.get("loader_kwargs", {})
+
common_params = {"headless": self.headless,
"verbose": self.verbose,
+ "loader_kwargs": self.loader_kwargs,
"llm_model": self.llm_model,
"embedder_model": self.embedder_model}
self.set_common_params(common_params, overwrite=False)
diff --git a/scrapegraphai/graphs/smart_scraper_graph.py b/scrapegraphai/graphs/smart_scraper_graph.py
index a9e63823..cef674a3 100644
--- a/scrapegraphai/graphs/smart_scraper_graph.py
+++ b/scrapegraphai/graphs/smart_scraper_graph.py
@@ -57,7 +57,10 @@ class SmartScraperGraph(AbstractGraph):
"""
fetch_node = FetchNode(
input="url | local_dir",
- output=["doc"]
+ output=["doc"],
+ node_config={
+ "loader_kwargs": self.config.get("loader_kwargs", {}),
+ }
)
parse_node = ParseNode(
input="doc",
diff --git a/scrapegraphai/nodes/fetch_node.py b/scrapegraphai/nodes/fetch_node.py
index 73363917..baf48615 100644
--- a/scrapegraphai/nodes/fetch_node.py
+++ b/scrapegraphai/nodes/fetch_node.py
@@ -49,6 +49,9 @@ class FetchNode(BaseNode):
self.verbose = (
False if node_config is None else node_config.get("verbose", False)
)
+ self.loader_kwargs = (
+ {} if node_config is None else node_config.get("loader_kwargs", {})
+ )
def execute(self, state):
"""
diff --git a/scrapegraphai/utils/proxy_rotation.py b/scrapegraphai/utils/proxy_rotation.py
index 0ca204e0..e3421cc1 100644
--- a/scrapegraphai/utils/proxy_rotation.py
+++ b/scrapegraphai/utils/proxy_rotation.py
@@ -161,7 +161,7 @@ def _search_proxy(proxy: Proxy) -> ProxySettings:
Returns:
A 'playwright' compliant proxy configuration.
"""
- server = search_proxy_servers(max_shape=1, **proxy.get("criteria", {}))[0]
+ server = search_proxy_servers(**proxy.get("criteria", {}))[0]
return {"server": server}