Apify Actors는 웹 스크래핑, 크롤링 및 데이터 추출 작업을 위해 설계된 클라우드 프로그램입니다. 이러한 Actor들은 웹에서 자동화된 데이터 수집을 용이하게 하여 사용자가 정보를 효율적으로 추출, 처리 및 저장할 수 있도록 합니다. Actor는 전자상거래 사이트에서 제품 세부 정보를 스크래핑하거나, 가격 변동을 모니터링하거나, 검색 엔진 결과를 수집하는 등의 작업을 수행하는 데 사용할 수 있습니다. Apify Datasets와 원활하게 통합되어 Actor가 수집한 구조화된 데이터를 저장, 관리하고 JSON, CSV 또는 Excel과 같은 형식으로 내보내 추가 분석이나 사용에 활용할 수 있습니다.

Overview

이 노트북은 Apify Actors를 LangChain과 함께 사용하여 웹 스크래핑 및 데이터 추출을 자동화하는 방법을 안내합니다. langchain-apify 패키지는 Apify의 클라우드 기반 도구를 LangChain agent와 통합하여 AI 애플리케이션을 위한 효율적인 데이터 수집 및 처리를 가능하게 합니다.

Setup

이 통합은 langchain-apify 패키지에 포함되어 있습니다. 이 패키지는 pip를 사용하여 설치할 수 있습니다.
pip install langchain-apify

Prerequisites

  • Apify 계정: 여기에서 무료 Apify 계정을 등록하세요.
  • Apify API token: Apify 문서에서 API token을 얻는 방법을 확인하세요.
import os

os.environ["APIFY_API_TOKEN"] = "your-apify-api-token"
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"

Instantiation

여기서는 RAG Web Browser Apify Actor를 호출할 수 있도록 ApifyActorsTool을 인스턴스화합니다. 이 Actor는 ChatGPT의 웹 브라우징 기능과 유사하게 AI 및 LLM 애플리케이션을 위한 웹 브라우징 기능을 제공합니다. Apify Store의 모든 Actor를 이러한 방식으로 사용할 수 있습니다.
from langchain_apify import ApifyActorsTool

tool = ApifyActorsTool("apify/rag-web-browser")

Invocation

ApifyActorsTool은 단일 인수를 받으며, 이는 run_input입니다 - Actor에 실행 입력으로 전달되는 dictionary입니다. 실행 입력 스키마 문서는 Actor 세부 정보 페이지의 input 섹션에서 찾을 수 있습니다. RAG Web Browser input schema를 참조하세요.
tool.invoke({"run_input": {"query": "what is apify?", "maxResults": 2}})

Chaining

생성된 tool을 agent에 제공할 수 있습니다. 정보 검색을 요청받으면 agent는 Apify Actor를 호출하고, Actor는 웹을 검색한 다음 검색 결과를 반환합니다.
pip install langgraph langchain-openai
from langchain.messages import ToolMessage
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent


model = ChatOpenAI(model="gpt-4o")
tools = [tool]
graph = create_agent(model, tools=tools)
inputs = {"messages": [("user", "search for what is Apify")]}
for s in graph.stream(inputs, stream_mode="values"):
    message = s["messages"][-1]
    # skip tool messages
    if isinstance(message, ToolMessage):
        continue
    message.pretty_print()
================================ Human Message =================================

search for what is Apify
================================== Ai Message ==================================
Tool Calls:
  apify_actor_apify_rag-web-browser (call_27mjHLzDzwa5ZaHWCMH510lm)
 Call ID: call_27mjHLzDzwa5ZaHWCMH510lm
  Args:
    run_input: {"run_input":{"query":"Apify","maxResults":3,"outputFormats":["markdown"]}}
================================== Ai Message ==================================

Apify is a comprehensive platform for web scraping, browser automation, and data extraction. It offers a wide array of tools and services that cater to developers and businesses looking to extract data from websites efficiently and effectively. Here's an overview of Apify:

1. **Ecosystem and Tools**:
   - Apify provides an ecosystem where developers can build, deploy, and publish data extraction and web automation tools called Actors.
   - The platform supports various use cases such as extracting data from social media platforms, conducting automated browser-based tasks, and more.

2. **Offerings**:
   - Apify offers over 3,000 ready-made scraping tools and code templates.
   - Users can also build custom solutions or hire Apify's professional services for more tailored data extraction needs.

3. **Technology and Integration**:
   - The platform supports integration with popular tools and services like Zapier, GitHub, Google Sheets, Pinecone, and more.
   - Apify supports open-source tools and technologies such as JavaScript, Python, Puppeteer, Playwright, Selenium, and its own Crawlee library for web crawling and browser automation.

4. **Community and Learning**:
   - Apify hosts a community on Discord where developers can get help and share expertise.
   - It offers educational resources through the Web Scraping Academy to help users become proficient in data scraping and automation.

5. **Enterprise Solutions**:
   - Apify provides enterprise-grade web data extraction solutions with high reliability, 99.95% uptime, and compliance with SOC2, GDPR, and CCPA standards.

For more information, you can visit [Apify's official website](https://apify.com/) or their [GitHub page](https://github.com/apify) which contains their code repositories and further details about their projects.

API reference

이 통합을 사용하는 방법에 대한 자세한 내용은 git repository 또는 Apify integration documentation을 참조하세요.

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I