This project is a web scraping and AI interaction system that integrates with a Microsoft Copilot-like platform using Selenium, Flask, and various utilities. It fetches messages from an AI platform, processes the data, and serves it via a Flask API.
- Web Scraping: Selenium ile, bir web sitesinden AI mesajlarını çekme ve bunları işleme.
- Mesaj İşleme: AI tarafından gönderilen mesajlarda ön ek (prefix) temizleme ve özel kelime değişiklikleri yapma.
- Resim Tespiti: AI mesajlarındaki resim bağlantılarını kontrol etme.
- Kod Blokları: AI mesajlarından kod bloklarını çıkarma.
- Flask API: Web üzerinden yapılan istekleri işleyerek yanıtlar sağlama.
- Cookies ve LocalStorage Kaydetme: Tarayıcıda oturum bilgilerini kaydetme ve tekrar yükleme.
- API Anahtarı Doğrulaması: Güvenlik amacıyla API anahtarları ile doğrulama.
- Python 3.x
- Selenium
- Flask
- ChromeDriver
- Google Chrome
- API Anahtarları ve settings.json dosyası
-
Python Bağımlılıklarını Yükleyin:
pip install -r requirements.txt
-
ChromeDriver ve Google Chrome: Tarayıcı sürümünüze uygun ChromeDriver'ı buradan indirip projenizin kök dizinine yerleştirin.
-
settings.json:
settings.json
dosyasını aşağıdaki örneğe göre yapılandırın:{ "driver": { "chrome_driver_path": "path/to/chromedriver", "user_agent": "your_user_agent" }, "api": { "keys_file": "keys.txt", "response_messages": { "ai_message": "ai_message", "code_blocks": "code_blocks", "img_link": "img_link" } }, "cookies_path": "cookies.pkl", "localstorage_path": "localstorage.pkl", "log_messages": { "login_prompt": "Please log in.", "error_occurred": "An error occurred", "server_started": "Server started successfully" }, "xpath_code_blocks": "//pre[@class='code-block']", "xpath_user_input": "//textarea[@id='input']", "xpath_ai_message": "//div[@class='ai-message']", "xpath_img_container": "//div[@class='img-container']", "img_link_check_timeout": 10 }
-
API Anahtarları:
keys.txt
dosyasına, API anahtarlarınızı her satıra bir anahtar olacak şekilde ekleyin. -
Flask Sunucusunu Başlatın: Projeyi başlatmak için:
python app.py
GET /api
- yazi: AI'ya gönderilecek yazı.
- key: API anahtarınız.
curl "http://localhost:5000/api?yazi=Merhaba&key=your_api_key"
{
"ai_message": "Hello, how can I help you?",
"code_blocks": "def example(): pass",
"img_link": "https://example.com/image.jpg"
}
This project is licensed under the MIT License - see the LICENSE file for details.
- Web Scraping: Fetch and process AI messages from a website using Selenium.
- Message Processing: Clean up prefixes and replace specific words in AI-generated messages.
- Image Detection: Check for image links in AI messages.
- Code Block Extraction: Extract code blocks from AI responses.
- Flask API: Serve requests over a Flask API.
- Cookies and LocalStorage: Save and load session information in the browser.
- API Key Authentication: Secure the API using API keys.
- Python 3.x
- Selenium
- Flask
- ChromeDriver
- Google Chrome
- API Keys and settings.json file
-
Install Python Dependencies:
pip install -r requirements.txt
-
ChromeDriver and Google Chrome: Download the correct version of ChromeDriver from here and place it in the root directory of your project.
-
settings.json: Configure your
settings.json
file as shown below:{ "driver": { "chrome_driver_path": "path/to/chromedriver", "user_agent": "your_user_agent" }, "api": { "keys_file": "keys.txt", "response_messages": { "ai_message": "ai_message", "code_blocks": "code_blocks", "img_link": "img_link" } }, "cookies_path": "cookies.pkl", "localstorage_path": "localstorage.pkl", "log_messages": { "login_prompt": "Please log in.", "error_occurred": "An error occurred", "server_started": "Server started successfully" }, "xpath_code_blocks": "//pre[@class='code-block']", "xpath_user_input": "//textarea[@id='input']", "xpath_ai_message": "//div[@class='ai-message']", "xpath_img_container": "//div[@class='img-container']", "img_link_check_timeout": 10 }
-
API Keys: Add your API keys to
keys.txt
, one key per line. -
Start the Flask Server: To run the project:
python app.py
You can use the API like this:
GET /api
- yazi: The text to send to the AI.
- key: Your API key.
curl "http://localhost:5000/api?yazi=Hello&key=your_api_key"
{
"ai_message": "Hello, how can I help you?",
"code_blocks": "def example(): pass",
"img_link": "https://example.com/image.jpg"
}
This project is licensed under the MIT License - see the LICENSE file for details.