基于AI的Python爬虫
Go to file
2024-04-11 18:18:22 +02:00
.github removed files and refactoring of actions 2024-04-11 18:18:22 +02:00
docs add new node 2024-02-17 21:42:43 +01:00
examples removed files and refactoring of actions 2024-04-11 18:18:22 +02:00
manual deployement removed files and refactoring of actions 2024-04-11 18:18:22 +02:00
scrapegraphai fixed embedder_model config for local models 2024-04-10 11:00:52 +02:00
tests DEV gemini support for simple custom graph 2024-03-14 19:35:04 +01:00
.gitattributes Initial commit 2024-01-27 17:54:23 +01:00
.gitignore fixed variable name 2024-04-06 20:08:50 +02:00
citation.cff add quotation file 2024-03-04 10:36:31 +01:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2024-02-05 10:20:57 +01:00
CONTRIBUTING.md upd: updated readme and fixed setup.py 2024-02-15 01:30:51 +01:00
docker-compose.yml docker compose working ollama implementation 2024-04-07 11:08:08 +02:00
LICENSE add new node 2024-02-17 21:42:43 +01:00
poetry.lock add new version 2024-04-10 09:49:01 +02:00
pyproject.toml add new version fixing embeddings 2024-04-10 12:25:24 +02:00
README.md add examples 2024-04-11 12:17:04 +02:00
readthedocs.yml changed the read the docs command 2024-02-15 08:58:03 +01:00
requirements-dev.txt add: poetry.toml for actions 2024-02-17 15:31:12 +01:00
requirements.txt docker compose working ollama implementation 2024-04-07 11:08:08 +02:00
SECURITY.md changed documentation + fixed a typo for the path 2024-02-07 16:56:03 +01:00

🕷️ ScrapeGraphAI: You Only Scrape Once

Downloads linting: pylint Pylint License: MIT

ScrapeGraphAI is a web scraping python library which uses LLM and direct graph logic to create scraping pipelines for websites, documents and XML files. Just say which information you want to extract and the library will do it for you!

Scrapegraph-ai Logo

🚀 Quick install

The reference page for Scrapegraph-ai is avaible on the official page of pypy: pypi.

pip install scrapegraphai

🔍 Demo

Official streamlit demo:

My Skills

Try it directly on the web using Google Colab:

Open In Colab

Follow the procedure on the following link to setup your OpenAI API key: link.

📖 Documentation

The documentation for ScrapeGraphAI can be found here.

Check out also the docusaurus documentation.

💻 Usage

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.

Case 1: Extracting informations using Ollama

Remember to download the model on Ollama separately!

from scrapegraphai.graphs import SmartScraperGraph

graph_config = {
    "llm": {
        "model": "ollama/mistral",
        "temperature": 0,
        "format": "json",  # Ollama needs the format to be specified explicitly
        "base_url": "http://localhost:11434",  # set ollama URL arbitrarily
    },
    "embeddings": {
        "model": "ollama/nomic-embed-text",
        "temperature": 0,
        "base_url": "http://localhost:11434",  # set ollama URL arbitrarily
    }
}

smart_scraper_graph = SmartScraperGraph(
    prompt="List me all the news with their description.",
    # also accepts a string with the already downloaded HTML code
    source="https://perinim.github.io/projects",
    config=graph_config
)

result = smart_scraper_graph.run()
print(result)

Case 2: Extracting informations using Docker

Note: before using the local model remeber to create the docker container!

    docker-compose up -d
    docker exec -it ollama ollama run stablelm-zephyr

You can use which models avaiable on Ollama or your own model instead of stablelm-zephyr

from scrapegraphai.graphs import SmartScraperGraph

graph_config = {
    "llm": {
        "model": "ollama/mistral",
        "temperature": 0,
        "format": "json",  # Ollama needs the format to be specified explicitly
        # "model_tokens": 2000, # set context length arbitrarily
    },
}

smart_scraper_graph = SmartScraperGraph(
    prompt="List me all the news with their description.",
    # also accepts a string with the already downloaded HTML code
    source="https://www.wired.com",
    config=graph_config
)

result = smart_scraper_graph.run()
print(result)

Case 3: Extracting informations using Openai model

from scrapegraphai.graphs import SmartScraperGraph
OPENAI_API_KEY = "YOUR_API_KEY"

graph_config = {
    "llm": {
        "api_key": OPENAI_API_KEY,
        "model": "gpt-3.5-turbo",
    },
}

smart_scraper_graph = SmartScraperGraph(
    prompt="List me all the news with their description.",
    # also accepts a string with the already downloaded HTML code
    source="https://www.wired.com",
    config=graph_config
)

result = smart_scraper_graph.run()
print(result)

Case 4: Extracting informations using Gemini

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 ",
    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:

{
    'titles': [
        'Rotary Pendulum RL'
        ],
    'descriptions': [
        'Open Source project aimed at controlling a real life rotary pendulum using RL algorithms'
        ]
}

🤝 Contributing

Fell free to contribute and join our Discord server to discuss with us improvements and give us suggestions!

For more information, please see the contributing guidelines.

My Skills My Skills My Skills

❤️ Contributors

Contributors

🎓 Citations

If you have used our library for research purposes please quote us with the following reference:

  @misc{scrapegraph-ai,
    author = {Marco Perini, Lorenzo Padoan, Marco Vinciguerra},
    title = {Scrapegraph-ai},
    year = {2024},
    url = {https://github.com/VinciGit00/Scrapegraph-ai},
    note = {A Python library for scraping data from graphs}
  }

Authors

Authors Logos

Contact Info
Marco Vinciguerra Linkedin Badge
Marco Perini Linkedin Badge
Lorenzo Padoan Linkedin Badge

📜 License

ScrapeGraphAI is licensed under the MIT License. See the LICENSE file for more information.

Acknowledgements

  • We would like to thank all the contributors to the project and the open-source community for their support.
  • ScrapeGraphAI is meant to be used for data exploration and research purposes only. We are not responsible for any misuse of the library.