ScrapeGraphAI - AI를 활용한 웹 스크래핑 라이브러리
ScrapeGraphAI: LLM과 그래프 로직을 활용한 웹 스크래핑 라이브러리
ScrapeGraphAI는 LLM(대형 언어 모델)과 직접적인 그래프 로직을 사용하여 웹사이트 및 로컬 문서(XML, HTML, JSON 등)의 스크래핑 파이프라인을 생성하는 파이썬 라이브러리입니다. 원하는 정보를 말하면 라이브러리가 자동으로 이를 추출해 줍니다!
🚀 설치
ScrapeGraphAI는 PyPI에서 설치할 수 있습니다:
pip install scrapegraphai
참고: 다른 라이브러리와의 충돌을 피하기 위해 가상 환경에서 설치하는 것을 권장합니다 🐱
🔍 데모
📖 문서
ScrapeGraphAI의 문서는 여기에서 찾을 수 있습니다.
또한 Docusaurus 문서를 여기에서 확인하세요.
💻 사용 방법
웹사이트(또는 로컬 파일)에서 정보를 추출하기 위해 사용할 수 있는 주요 스크래핑 파이프라인은 다음과 같습니다:
SmartScraperGraph: 사용자 프롬프트와 입력 소스만 필요로 하는 단일 페이지 스크래퍼SearchGraph: 검색 엔진의 상위 n개의 검색 결과에서 정보를 추출하는 다중 페이지 스크래퍼SpeechGraph: 웹사이트에서 정보를 추출하고 오디오 파일을 생성하는 단일 페이지 스크래퍼SmartScraperMultiGraph: 단일 프롬프트를 사용하여 여러 페이지를 스크래핑
API를 통해 OpenAI, Groq, Azure, Gemini와 같은 다양한 LLM을 사용할 수 있으며, Ollama를 사용하여 로컬 모델도 사용할 수 있습니다.
사례 1: 로컬 모델을 사용한 SmartScraper
Ollama를 설치하고 ollama pull 명령어로 모델을 다운로드하세요.
from scrapegraphai.graphs import SmartScraperGraph
graph_config = {
"llm": {
"model": "ollama/mistral",
"temperature": 0,
"format": "json",
"base_url": "http://localhost:11434",
},
"embeddings": {
"model": "ollama/nomic-embed-text",
"base_url": "http://localhost:11434",
},
"verbose": True,
}
smart_scraper_graph = SmartScraperGraph(
prompt="프로젝트와 설명을 모두 나열해 주세요",
source="https://perinim.github.io/projects",
config=graph_config
)
result = smart_scraper_graph.run()
print(result)
출력은 다음과 같은 프로젝트 목록이 될 것입니다:
{'projects': [{'title': 'Rotary Pendulum RL', 'description': 'RL 알고리즘을 사용하여 실제 회전 진자를 제어하는 오픈 소스 프로젝트'}, {'title': 'DQN Implementation from scratch', 'description': '간단한 펜듈럼과 더블 펜듈럼을 훈련시키기 위한 딥 Q-네트워크 알고리즘을 개발함'}, ...]}
사례 2: 혼합 모델을 사용한 SearchGraph
LLM은 Groq을, 임베딩은 Ollama를 사용합니다.
from scrapegraphai.graphs import SearchGraph
graph_config = {
"llm": {
"model": "groq/gemma-7b-it",
"api_key": "GROQ_API_KEY",
"temperature": 0
},
"embeddings": {
"model": "ollama/nomic-embed-text",
"base_url": "http://localhost:11434",
},
"max_results": 5,
}
search_graph = SearchGraph(
prompt="Chioggia의 전통 레시피를 모두 나열해 주세요",
config=graph_config
)
result = search_graph.run()
print(result)
출력은 다음과 같은 레시피 목록이 될 것입니다:
{'recipes': [{'name': 'Sarde in Saòre'}, {'name': 'Bigoli in salsa'}, {'name': 'Seppie in umido'}, {'name': 'Moleche frite'}, {'name': 'Risotto alla pescatora'}, {'name': 'Broeto'}, {'name': 'Bibarasse in Cassopipa'}, {'name': 'Risi e bisi'}, {'name': 'Smegiassa Ciosota'}]}
사례 3: OpenAI를 사용한 SpeechGraph
OpenAI API 키와 모델 이름을 전달하기만 하면 됩니다.
from scrapegraphai.graphs import SpeechGraph
graph_config = {
"llm": {
"api_key": "OPENAI_API_KEY",
"model": "gpt-3.5-turbo",
},
"tts_model": {
"api_key": "OPENAI_API_KEY",
"model": "tts-1",
"voice": "alloy"
},
"output_path": "audio_summary.mp3",
}
speech_graph = SpeechGraph(
prompt="프로젝트의 자세한 오디오 요약을 만들어 주세요.",
source="https://perinim.github.io/projects/",
config=graph_config,
)
result = speech_graph.run()
print(result)
출력은 페이지에 있는 프로젝트 요약이 담긴 오디오 파일이 될 것입니다.
이 글은 ScrapeGraphAI 레포지토리의 README.md를 참고하여 작성되었습니다.

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.
Congratulations, your post has been upvoted by @upex with a 0.21% upvote. We invite you to continue producing quality content and join our Discord community here. Keep up the good work! #upex