Skip to content

Python scraper based on AI

add new version + refactoring of the code

VinciGit00958b2a4a7950
diff --git a/README.md b/README.md
index ad04e4cc..a3cbc6a6 100644
--- a/README.md
+++ b/README.md
@@ -43,12 +43,18 @@ Check out also the docusaurus [documentation](https://scrapegraph-doc.onrender.c
## 💻 Usage
-### Case 1: Extracting information using a prompt
+### Case 1: Extracting informations using a local LLM
You can use the `SmartScraper` class to extract information from a website using a prompt.
The `SmartScraper` class is a direct graph implementation that uses the most common nodes present in a web scraping pipeline. For more information, please see the [documentation](https://scrapegraph-ai.readthedocs.io/en/latest/).
+```python
+
+```
+
+
+### Case 2: Extracting informations using Openai model
```python
from scrapegraphai.graphs import SmartScraperGraph
OPENAI_API_KEY = "YOUR_API_KEY"
@@ -72,7 +78,31 @@ result = smart_scraper_graph.run()
print(result)
```
-The output will be a dictionary with the extracted information, for example:
+### Case 3: Extracting informations using Gemini
+```python
+from scrapegraphai.graphs import SmartScraperGraph
+GOOGLE_APIKEY = "YOUR_API_KEY"
+
+# Define the configuration for the graph
+graph_config = {
+ "llm": {
+ "api_key": GOOGLE_APIKEY,
+ "model": "gemini-pro",
+ },
+}
+
+# Create the SmartScraperGraph instance
+smart_scraper_graph = SmartScraperGraph(
+ prompt="List me all the quotes, authors and tags ",
+ file_source="http://quotes.toscrape.com", # also accepts a string with the already downloaded HTML code as string format
+ config=graph_config
+)
+
+result = smart_scraper_graph.run()
+print(result)
+```
+
+The output for alle 3 the cases will be a dictionary with the extracted information, for example:
```bash
{
diff --git a/examples/custom_graph_gemini.py b/examples/gemini/custom_graph_gemini.py
similarity index 97%
rename from examples/custom_graph_gemini.py
rename to examples/gemini/custom_graph_gemini.py
index 7d663773..4380bd53 100644
--- a/examples/custom_graph_gemini.py
+++ b/examples/gemini/custom_graph_gemini.py
@@ -7,7 +7,6 @@ from dotenv import load_dotenv
from scrapegraphai.models import Gemini
from scrapegraphai.graphs import BaseGraph
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
-from scrapegraphai.helpers import models_tokens
load_dotenv()
# ************************************************
diff --git a/examples/custom_graph_openai.py b/examples/openai/custom_graph_openai.py
similarity index 97%
rename from examples/custom_graph_openai.py
rename to examples/openai/custom_graph_openai.py
index d92cf3dd..98ebcea3 100644
--- a/examples/custom_graph_openai.py
+++ b/examples/openai/custom_graph_openai.py
@@ -7,7 +7,6 @@ from dotenv import load_dotenv
from scrapegraphai.models import OpenAI
from scrapegraphai.graphs import BaseGraph
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
-from scrapegraphai.helpers import models_tokens
load_dotenv()
# ************************************************
@@ -82,4 +81,4 @@ result = graph.execute({
# get the answer from the result
result = result.get("answer", "No answer found.")
-print(result)
\ No newline at end of file
+print(result)
diff --git a/examples/inputs/books.xml b/examples/openai/inputs/books.xml
similarity index 100%
rename from examples/inputs/books.xml
rename to examples/openai/inputs/books.xml
diff --git a/examples/inputs/plain_html_example.txt b/examples/openai/inputs/plain_html_example.txt
similarity index 100%
rename from examples/inputs/plain_html_example.txt
rename to examples/openai/inputs/plain_html_example.txt
diff --git a/examples/results/result.csv b/examples/openai/results/result.csv
similarity index 100%
rename from examples/results/result.csv
rename to examples/openai/results/result.csv
diff --git a/examples/results/result.json b/examples/openai/results/result.json
similarity index 100%
rename from examples/results/result.json
rename to examples/openai/results/result.json
diff --git a/examples/scrape_plain_text.py b/examples/openai/scrape_plain_text.py
similarity index 100%
rename from examples/scrape_plain_text.py
rename to examples/openai/scrape_plain_text.py
diff --git a/examples/scrape_xml_document.py b/examples/openai/scrape_xml_document.py
similarity index 100%
rename from examples/scrape_xml_document.py
rename to examples/openai/scrape_xml_document.py
diff --git a/examples/search_graph_example.py b/examples/openai/search_graph_example.py
similarity index 100%
rename from examples/search_graph_example.py
rename to examples/openai/search_graph_example.py
diff --git a/examples/smart_scraper_example.py b/examples/openai/smart_scraper_example.py
similarity index 100%
rename from examples/smart_scraper_example.py
rename to examples/openai/smart_scraper_example.py
diff --git a/examples/speech_graph_example.py b/examples/openai/speech_graph_example.py
similarity index 100%
rename from examples/speech_graph_example.py
rename to examples/openai/speech_graph_example.py
diff --git a/pyproject.toml b/pyproject.toml
index 649ee00a..22ffb592 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "scrapegraphai"
-version = "0.0.16"
+version = "0.1.0"
description = "A web scraping library based on LangChain which uses LLM and direct graph logic to create scraping pipelines."
authors = [
"Marco Vinciguerra <[email protected]>",