تحليل المنافسين الآلي باستخدام ScrapeGraph و Gemini AI: دليل شامل
يقدم هذا الدليل الشامل طريقة فعّالة وآلية لتحليل المنافسين في السوق، وذلك من خلال دمج قدرات ScrapeGraph القوية في استخراج البيانات من الويب مع قدرات نموذج اللغة الكبير Gemini AI في تحليلها وتفسيرها. سنتعلم كيفية بناء سير عمل قابل للتطوير يوفر رؤى استراتيجية قيّمة حول السوق والمنافسين.
1. إعداد بيئة العمل
قبل البدء، يجب تثبيت المكتبات اللازمة لتشغيل الكود. يمكنك القيام بذلك باستخدام الأمر التالي في محيط Python:
pip install --quiet -U langchain-scrapegraph langchain-google-genai pandas matplotlib seaborn
هذه المكتبات تضم:
langchain-scrapegraph
: لاستخراج البيانات من المواقع الإلكترونية.langchain-google-genai
: للتكامل مع نموذج Gemini AI.pandas
,matplotlib
,seaborn
: لتحليل البيانات وعرضها بيانياً.
بعد ذلك، قم باستيراد المكتبات الضرورية في برنامج Python الخاص بك:
import getpass
import os
import json
import pandas as pd
from typing import List, Dict, Any
from datetime import datetime
import matplotlib.pyplot as plt
import seaborn as sns
ثم، قم بتعيين مفاتيح API الخاصة بك:
if not os.environ.get("SGAI_API_KEY"):
os.environ["SGAI_API_KEY"] = getpass.getpass("ScrapeGraph AI API key:n")
if not os.environ.get("GOOGLE_API_KEY"):
os.environ["GOOGLE_API_KEY"] = getpass.getpass("Google API key for Gemini:n")
2. استخدام أدوات ScrapeGraph و Gemini AI
نقوم باستيراد وتفعيل أدوات ScrapeGraph وتهيئة نموذج Gemini AI:
from langchain_scrapegraph.tools import (
SmartScraperTool,
SearchScraperTool,
MarkdownifyTool,
GetCreditsTool,
)
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableConfig, chain
from langchain_core.output_parsers import JsonOutputParser
smartscraper = SmartScraperTool()
searchscraper = SearchScraperTool()
markdownify = MarkdownifyTool()
credits = GetCreditsTool()
llm = ChatGoogleGenerativeAI(
model="gemini-1.5-flash", temperature=0.1, convert_system_message_to_human=True
)
3. فئة CompetitiveAnalyzer
هذه الفئة تُنسّق عملية تحليل المنافسين من البداية إلى النهاية:
class CompetitiveAnalyzer:
def __init__(self):
self.results = []
self.analysis_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# ... (rest of the CompetitiveAnalyzer class code as provided in the original post) ...
3.1. وظيفة scrape_competitor_data
تقوم هذه الوظيفة باستخراج البيانات من موقع منافس معين:
def scrape_competitor_data(self, url: str, company_name: str = None) -> Dict[str, Any]:
"""Scrape comprehensive data from a competitor website"""
# ... (code as provided in the original post) ...
3.2. وظيفة analyze_competitor_landscape
تحلل هذه الوظيفة بيانات متعددة للمنافسين وتولّد رؤى شاملة باستخدام Gemini AI:
def analyze_competitor_landscape(self, competitors: List[Dict[str, str]]) -> Dict[str, Any]:
"""Analyze multiple competitors and generate insights"""
# ... (code as provided in the original post) ...
3.3. وظائف إضافية
تتضمن الفئة أيضاً وظائف لإنشاء إحصائيات موجزة (generate_summary_stats
) وتصدير النتائج إلى ملفات JSON و CSV (export_results
).
4. تشغيل التحليل
يوفر هذا القسم أمثلة على كيفية استخدام الفئة CompetitiveAnalyzer
لتحليل منافسين في قطاعي AI/SaaS و التجارة الإلكترونية:
def run_ai_saas_analysis():
# ... (code as provided in the original post) ...
def run_ecommerce_analysis():
# ... (code as provided in the original post) ...
def check_credits():
# ... (code as provided in the original post) ...
if __name__ == "__main__":
# ... (code as provided in the original post) ...
5. مراقبة وسائل التواصل الاجتماعي (Social Media Monitoring)
يوفر هذا القسم دالة إضافية لمراقبة حضور المنافسين على وسائل التواصل الاجتماعي:
@chain
def social_media_monitoring_chain(company_urls: List[str], config: RunnableConfig):
# ... (code as provided in the original post) ...
6. الخلاصة
يُعدّ دمج ScrapeGraph و Gemini AI طريقة فعّالة لتحليل المنافسين، مما يوفر الوقت والجهد ويُمكّن المحللين من التركيز على تفسير النتائج الاستراتيجية بدلاً من جمع البيانات يدوياً. يوفر هذا الدليل إطاراً شاملاً لبناء سير عمل قابل للتطوير لجمع وتحليل بيانات المنافسين بشكل آلي ودقيق. يمكنك الاطلاع على المزيد من التفاصيل في [رابط Github](أضف رابط جيثب هنا).
اترك تعليقاً