Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
add examples for deepseek
VinciGit007c91f9f94c55
diff --git a/examples/deepseek/.env.example b/examples/deepseek/.env.examplenew file mode 100644index 00000000..12c1491c--- /dev/null+++ b/examples/deepseek/.env.example@@ -0,0 +1 @@+OPENAI_APIKEY="your openai api key"\ No newline at end of filediff --git a/examples/deepseek/csv_scraper_deepseek.py b/examples/deepseek/csv_scraper_deepseek.pynew file mode 100644index 00000000..b734b543--- /dev/null+++ b/examples/deepseek/csv_scraper_deepseek.py@@ -0,0 +1,58 @@+"""+Basic example of scraping pipeline using CSVScraperGraph from CSV documents+"""++import os+from dotenv import load_dotenv+import pandas as pd+from scrapegraphai.graphs import CSVScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the CSV file+# ************************************************++FILE_NAME = "inputs/username.csv"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++text = pd.read_csv(file_path)++# ************************************************+# Define the configuration for the graph+# ************************************************++deepseek_key = os.getenv("DEEPSEEK_APIKEY")++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "verbose": True,+}+# ************************************************+# Create the CSVScraperGraph instance and run it+# ************************************************++csv_scraper_graph = CSVScraperGraph(+ prompt="List me all the last names",+ source=str(text), # Pass the content of the file, not the file object+ config=graph_config+)++result = csv_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = csv_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/deepseek/inputs/books.xml b/examples/deepseek/inputs/books.xmlnew file mode 100644index 00000000..e3d1fe87--- /dev/null+++ b/examples/deepseek/inputs/books.xml@@ -0,0 +1,120 @@+<?xml version="1.0"?>+<catalog>+ <book id="bk101">+ <author>Gambardella, Matthew</author>+ <title>XML Developer's Guide</title>+ <genre>Computer</genre>+ <price>44.95</price>+ <publish_date>2000-10-01</publish_date>+ <description>An in-depth look at creating applications+ with XML.</description>+ </book>+ <book id="bk102">+ <author>Ralls, Kim</author>+ <title>Midnight Rain</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-12-16</publish_date>+ <description>A former architect battles corporate zombies,+ an evil sorceress, and her own childhood to become queen+ of the world.</description>+ </book>+ <book id="bk103">+ <author>Corets, Eva</author>+ <title>Maeve Ascendant</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-11-17</publish_date>+ <description>After the collapse of a nanotechnology+ society in England, the young survivors lay the+ foundation for a new society.</description>+ </book>+ <book id="bk104">+ <author>Corets, Eva</author>+ <title>Oberon's Legacy</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-03-10</publish_date>+ <description>In post-apocalypse England, the mysterious+ agent known only as Oberon helps to create a new life+ for the inhabitants of London. Sequel to Maeve+ Ascendant.</description>+ </book>+ <book id="bk105">+ <author>Corets, Eva</author>+ <title>The Sundered Grail</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-09-10</publish_date>+ <description>The two daughters of Maeve, half-sisters,+ battle one another for control of England. Sequel to+ Oberon's Legacy.</description>+ </book>+ <book id="bk106">+ <author>Randall, Cynthia</author>+ <title>Lover Birds</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-09-02</publish_date>+ <description>When Carla meets Paul at an ornithology+ conference, tempers fly as feathers get ruffled.</description>+ </book>+ <book id="bk107">+ <author>Thurman, Paula</author>+ <title>Splish Splash</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>A deep sea diver finds true love twenty+ thousand leagues beneath the sea.</description>+ </book>+ <book id="bk108">+ <author>Knorr, Stefan</author>+ <title>Creepy Crawlies</title>+ <genre>Horror</genre>+ <price>4.95</price>+ <publish_date>2000-12-06</publish_date>+ <description>An anthology of horror stories about roaches,+ centipedes, scorpions and other insects.</description>+ </book>+ <book id="bk109">+ <author>Kress, Peter</author>+ <title>Paradox Lost</title>+ <genre>Science Fiction</genre>+ <price>6.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>After an inadvertant trip through a Heisenberg+ Uncertainty Device, James Salway discovers the problems+ of being quantum.</description>+ </book>+ <book id="bk110">+ <author>O'Brien, Tim</author>+ <title>Microsoft .NET: The Programming Bible</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-09</publish_date>+ <description>Microsoft's .NET initiative is explored in+ detail in this deep programmer's reference.</description>+ </book>+ <book id="bk111">+ <author>O'Brien, Tim</author>+ <title>MSXML3: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-01</publish_date>+ <description>The Microsoft MSXML3 parser is covered in+ detail, with attention to XML DOM interfaces, XSLT processing,+ SAX and more.</description>+ </book>+ <book id="bk112">+ <author>Galos, Mike</author>+ <title>Visual Studio 7: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>49.95</price>+ <publish_date>2001-04-16</publish_date>+ <description>Microsoft Visual Studio 7 is explored in depth,+ looking at how Visual Basic, Visual C++, C#, and ASP+ are+ integrated into a comprehensive development+ environment.</description>+ </book>+</catalog>\ No newline at end of filediff --git a/examples/deepseek/inputs/example.json b/examples/deepseek/inputs/example.jsonnew file mode 100644index 00000000..2263184c--- /dev/null+++ b/examples/deepseek/inputs/example.json@@ -0,0 +1,182 @@+{+ "kind":"youtube#searchListResponse",+ "etag":"q4ibjmYp1KA3RqMF4jFLl6PBwOg",+ "nextPageToken":"CAUQAA",+ "regionCode":"NL",+ "pageInfo":{+ "totalResults":1000000,+ "resultsPerPage":5+ },+ "items":[+ {+ "kind":"youtube#searchResult",+ "etag":"QCsHBifbaernVCbLv8Cu6rAeaDQ",+ "id":{+ "kind":"youtube#video",+ "videoId":"TvWDY4Mm5GM"+ },+ "snippet":{+ "publishedAt":"2023-07-24T14:15:01Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Football Clubs Kylian Mbappe Should Avoid Signing ✍️❌⚽️ #football #mbappe #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T14:15:01Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"0NG5QHdtIQM_V-DBJDEf-jK_Y9k",+ "id":{+ "kind":"youtube#video",+ "videoId":"aZM_42CcNZ4"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:09:27Z",+ "channelId":"UCM5gMM_HqfKHYIEJ3lstMUA",+ "title":"Which Football Club Could Cristiano Ronaldo Afford To Buy? 💰",+ "description":"Sign up to Sorare and get a FREE card: https://sorare.pxf.io/NellisShorts Give Soraredata a go for FREE: ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"John Nellis",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:09:27Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"WbBz4oh9I5VaYj91LjeJvffrBVY",+ "id":{+ "kind":"youtube#video",+ "videoId":"wkP3XS3aNAY"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:00:50Z",+ "channelId":"UC4EP1dxFDPup_aFLt0ElsDw",+ "title":"PAULO DYBALA vs THE WORLD'S LONGEST FREEKICK WALL",+ "description":"Can Paulo Dybala curl a football around the World's longest free kick wall? We met up with the World Cup winner and put him to ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Shoot for Love",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:00:50Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"juxv_FhT_l4qrR05S1QTrb4CGh8",+ "id":{+ "kind":"youtube#video",+ "videoId":"rJkDZ0WvfT8"+ },+ "snippet":{+ "publishedAt":"2023-07-24T10:00:39Z",+ "channelId":"UCO8qj5u80Ga7N_tP3BZWWhQ",+ "title":"TOP 10 DEFENDERS 2023",+ "description":"SoccerKingz https://soccerkingz.nl Use code: 'ILOVEHOF' to get 10% off. TOP 10 DEFENDERS 2023 Follow us! • Instagram ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Home of Football",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T10:00:39Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"wtuknXTmI1txoULeH3aWaOuXOow",+ "id":{+ "kind":"youtube#video",+ "videoId":"XH0rtu4U6SE"+ },+ "snippet":{+ "publishedAt":"2023-07-21T16:30:05Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Things You Didn't Know About Erling Haaland ⚽️🇳🇴 #football #haaland #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-21T16:30:05Z"+ }+ }+ ]+}\ No newline at end of filediff --git a/examples/deepseek/inputs/username.csv b/examples/deepseek/inputs/username.csvnew file mode 100644index 00000000..006ac8e6--- /dev/null+++ b/examples/deepseek/inputs/username.csv@@ -0,0 +1,7 @@+Username; Identifier;First name;Last name+booker12;9012;Rachel;Booker+grey07;2070;Laura;Grey+johnson81;4081;Craig;Johnson+jenkins46;9346;Mary;Jenkins+smith79;5079;Jamie;Smith+diff --git a/examples/deepseek/json_scraper_deepseek.py b/examples/deepseek/json_scraper_deepseek.pynew file mode 100644index 00000000..dfe6f489--- /dev/null+++ b/examples/deepseek/json_scraper_deepseek.py@@ -0,0 +1,58 @@+"""+Basic example of scraping pipeline using JSONScraperGraph from JSON documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the JSON file+# ************************************************+deepseek_key = os.getenv("DEEPSEEK_APIKEY")++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "verbose": True,+}++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++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+ config=graph_config+)++result = json_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = json_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/deepseek/script_generator_deepseek.py b/examples/deepseek/script_generator_deepseek.pynew file mode 100644index 00000000..fd5fd4dd--- /dev/null+++ b/examples/deepseek/script_generator_deepseek.py@@ -0,0 +1,46 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++deepseek_key = os.getenv("DEEPSEEK_APIKEY")++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "library": "beautifulsoup"+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/deepseek/search_graph_deepseek.py b/examples/deepseek/search_graph_deepseek.pynew file mode 100644index 00000000..74944370--- /dev/null+++ b/examples/deepseek/search_graph_deepseek.py@@ -0,0 +1,48 @@+"""+Example of Search Graph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++deepseek_key = os.getenv("DEEPSEEK_APIKEY")++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "max_results": 2,+ "verbose": True,+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/deepseek/xml_scraper_deepseek.py b/examples/deepseek/xml_scraper_deepseek.pynew file mode 100644index 00000000..ba401b91--- /dev/null+++ b/examples/deepseek/xml_scraper_deepseek.py@@ -0,0 +1,61 @@+"""+Basic example of scraping pipeline using XMLScraperGraph from XML documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import XMLScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the XML file+# ************************************************++FILE_NAME = "inputs/books.xml"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************+++deepseek_key = os.getenv("DEEPSEEK_APIKEY")++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "verbose": True,+}+++# ************************************************+# Create the XMLScraperGraph instance and run it+# ************************************************++xml_scraper_graph = XMLScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = xml_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = xml_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/openai/.env.example b/examples/openai/.env.exampleindex 12c1491c..8e281644 100644--- a/examples/openai/.env.example+++ b/examples/openai/.env.example@@ -1 +1 @@-OPENAI_APIKEY="your openai api key"\ No newline at end of file+DEEPSEEK_APIKEY="your deepseek api key"\ No newline at end of file