|
| 1 | +Overview |
| 2 | +======== |
| 3 | + |
| 4 | +Here some example of the different ways to scrape with ScrapegraphAI |
| 5 | + |
| 6 | +OpenAI models |
| 7 | +^^^^^^^^^^^^^ |
| 8 | + |
| 9 | +.. code-block:: python |
| 10 | +
|
| 11 | + import os |
| 12 | + from dotenv import load_dotenv |
| 13 | + from scrapegraphai.graphs import SmartScraperGraph |
| 14 | + from scrapegraphai.utils import prettify_exec_info |
| 15 | +
|
| 16 | + load_dotenv() |
| 17 | +
|
| 18 | + openai_key = os.getenv("OPENAI_APIKEY") |
| 19 | +
|
| 20 | + graph_config = { |
| 21 | + "llm": { |
| 22 | + "api_key": openai_key, |
| 23 | + "model": "gpt-3.5-turbo", |
| 24 | + }, |
| 25 | + } |
| 26 | +
|
| 27 | + # ************************************************ |
| 28 | + # Create the SmartScraperGraph instance and run it |
| 29 | + # ************************************************ |
| 30 | +
|
| 31 | + smart_scraper_graph = SmartScraperGraph( |
| 32 | + prompt="List me all the projects with their description.", |
| 33 | + # also accepts a string with the already downloaded HTML code |
| 34 | + source="https://perinim.github.io/projects/", |
| 35 | + config=graph_config |
| 36 | + ) |
| 37 | +
|
| 38 | + result = smart_scraper_graph.run() |
| 39 | + print(result) |
| 40 | +
|
| 41 | +
|
| 42 | +OpenAI models |
| 43 | +^^^^^^^^^^^^^ |
| 44 | + |
| 45 | +.. code-block:: python |
| 46 | +
|
| 47 | + import os |
| 48 | + from dotenv import load_dotenv |
| 49 | + from scrapegraphai.graphs import SmartScraperGraph |
| 50 | + from scrapegraphai.utils import prettify_exec_info |
| 51 | +
|
| 52 | + load_dotenv() |
| 53 | +
|
| 54 | + openai_key = os.getenv("OPENAI_APIKEY") |
| 55 | +
|
| 56 | + graph_config = { |
| 57 | + "llm": { |
| 58 | + "api_key": openai_key, |
| 59 | + "model": "gpt-3.5-turbo", |
| 60 | + }, |
| 61 | + } |
| 62 | +
|
| 63 | + # ************************************************ |
| 64 | + # Create the SmartScraperGraph instance and run it |
| 65 | + # ************************************************ |
| 66 | +
|
| 67 | + smart_scraper_graph = SmartScraperGraph( |
| 68 | + prompt="List me all the projects with their description.", |
| 69 | + # also accepts a string with the already downloaded HTML code |
| 70 | + source="https://perinim.github.io/projects/", |
| 71 | + config=graph_config |
| 72 | + ) |
| 73 | +
|
| 74 | + result = smart_scraper_graph.run() |
| 75 | + print(result) |
| 76 | +
|
| 77 | +Local models |
| 78 | +^^^^^^^^^^^^^ |
| 79 | + |
| 80 | +Remember to have installed in your pc ollama `ollama <https://ollama.com/>` |
| 81 | +Remember to pull the right model for LLM and for the embeddings, like: |
| 82 | +.. code-block:: bash |
| 83 | +
|
| 84 | + ollama pull llama3 |
| 85 | +
|
| 86 | +After that, you can run the following code, using only your machine resources brum brum brum: |
| 87 | + |
| 88 | +.. code-block:: python |
| 89 | +
|
| 90 | + from scrapegraphai.graphs import SmartScraperGraph |
| 91 | + from scrapegraphai.utils import prettify_exec_info |
| 92 | +
|
| 93 | + graph_config = { |
| 94 | + "llm": { |
| 95 | + "model": "ollama/mistral", |
| 96 | + "temperature": 1, |
| 97 | + "format": "json", # Ollama needs the format to be specified explicitly |
| 98 | + "model_tokens": 2000, # depending on the model set context length |
| 99 | + "base_url": "http://localhost:11434", # set ollama URL of the local host (YOU CAN CHANGE IT, if you have a different endpoint |
| 100 | + }, |
| 101 | + "embeddings": { |
| 102 | + "model": "ollama/nomic-embed-text", |
| 103 | + "temperature": 0, |
| 104 | + "base_url": "http://localhost:11434", # set ollama URL |
| 105 | + } |
| 106 | + } |
| 107 | +
|
| 108 | + # ************************************************ |
| 109 | + # Create the SmartScraperGraph instance and run it |
| 110 | + # ************************************************ |
| 111 | +
|
| 112 | + smart_scraper_graph = SmartScraperGraph( |
| 113 | + prompt="List me all the news with their description.", |
| 114 | + # also accepts a string with the already downloaded HTML code |
| 115 | + source="https://perinim.github.io/projects", |
| 116 | + config=graph_config |
| 117 | + ) |
| 118 | +
|
| 119 | + result = smart_scraper_graph.run() |
| 120 | + print(result) |
| 121 | +
|
0 commit comments