0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルにFirecrawlをインストールしてハマった件

Posted at

私は、Dockerの事をほとんど理解してません。
https://zenn.dev/zozotech/articles/d177f4cdc02755
こちらの記事を参考にして、ローカルにFirecrawlをインストールしたがかなりハマった。

私の環境はWINDOWS11、WSL2、difyローカルはWSL2のdockerで動いてます。

AIと相談しながら、動いたので、現在の設定を残します。

git clone https://github.com/mendableai/firecrawl.git
cd firecrawl
cp ./apps/api/.env.example ./.env
#.env変更した設定は以下の通り
# ===== Required ENVS ======
NUM_WORKERS_PER_QUEUE=8
PORT=3002
HOST=0.0.0.0
REDIS_URL=redis://redis:6379 #for self-hosting using docker, use redis://redis:6379. For running locally, use redis://localhost:6379
REDIS_RATE_LIMIT_URL=redis://redis:6379 #for self-hosting using docker, use redis://redis:6379. For running locally, use redis://localhost:6379
PLAYWRIGHT_MICROSERVICE_URL=http://playwright-service:3000
## To turn on DB authentication, you need to set up supabase.
USE_DB_AUTHENTICATION=false #true
# ===== Optional ENVS ======
# Other Optionals
# use if you've set up authentication and want to test with a real API key
TEST_API_KEY=fc-test
LOGGING_LEVEL=INFO
#.env変更した設定は以上の通り
#firecrawl-apiのCONTAINER IDを見つけてログを出してみたらredisが無いとエラーが出てた
docker ps 
docker logs <firecrawl-apiのCONTAINER ID>
#redis-serverをインストール
sudo apt install redis-server
sudo systemctl start redis-server
sudo systemctl status redis-server

#このあたりで、マシンがWINDOWS11、wsl2のdockerでDify、firecrawl、redis、playwrightが動いてると分かった。
#この状況で、pythonから、firecrawlにアクセスするため、IPアドレスを調べた

hostname -I
#http://172.27.117.140 <=私の例
#一番左にある、IPアドレスが良いとのことで、それを使ってpythonからアクセスしたら、成功した!!
#ローカルのDifyのナレッジ => ナレッジを作成 => WEBサイトから同期 => Firecrawl => 設定のbase urlに
#http://172.27.117.140:3002を設定したら、Difyローカルから、Firecrawlローカルにアクセスできて、上限無くスクレイピング可能になった。
#pythonの例

import requests
import time

def post_with_infinite_retry(url, payload, headers, timeout=30, retry_interval=5):
    """
    指定した URL に対して POST リクエストを行い、
    エラーが発生した場合は retry_interval 秒ごとに再試行します。
    成功すればレスポンスを返します。
    """
    session = requests.Session()
    while True:
        try:
            response = session.post(url, json=payload, headers=headers, timeout=timeout)
            response.raise_for_status()  # HTTPエラーがあれば例外を発生させる
            return response
        except requests.exceptions.RequestException as e:
            print("リクエストエラー:", e)
            print("{}秒後に再試行します...".format(retry_interval))
            time.sleep(retry_interval)

if __name__ == '__main__':
    url = "http://172.27.117.140:3002/v1/scrape"
    payload = {
        "url": "https://google.com",      # スクレイプ対象のURL(必要に応じて変更)
        "formats": ["markdown"],           # 出力フォーマット
        "onlyMainContent": True            # ページの主要コンテンツのみ抽出
    }
    headers = {
        "Authorization": "Bearer fc-test",  # 実際の API キーに置き換えてください
        "Content-Type": "application/json"
    }
    
    print("Firecrawl API にアクセスを試みます...")
    response = post_with_infinite_retry(url, payload, headers)
    print("接続成功!レスポンス:")
    print(response.text)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?