Twitter’da artık daha fazla bot ve ilgilenmediğim içerikler görmeye başladım, bu da fazlasıyla zamanımı alıyordu. Bu istenmeyen içerikleri engellemek için bir proje geliştirmeye karar verdim ve Twitter API’sini kullanmayı düşündüm. Ancak, kelime engelleme özelliğinin API desteği olmadığını fark ettim.
Bunu çok dert etmeden, Selenium kullanarak bir script yazmaya karar verdim. Biraz manuel olsa da bu script gayet başarılı çalışıyor.
Yapmanız gerekenler:
Chrome’u Debug Modunda Çalıştırın
Chrome’u debug modunda çalıştırıp x.com’a login olun.
google-chrome --remote-debugging-port=9222 "https://x.com/"
Gerekli Python Kütüphanelerini Yükleyin
pip install selenium
Python Kodunu Çalıştırın
python your_script.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By import time from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC def add_muted_keyword(keyword): # Connect to an existing Chrome session on port 9222 options = webdriver.ChromeOptions() options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") driver = webdriver.Chrome(options=options) # Go to settings for muted words driver.get("https://x.com/settings/add_muted_keyword") WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@name='keyword']"))) # Click on the input field to activate it input_field = driver.find_element(By.XPATH, "//input[@name='keyword']") input_field.click() time.sleep(1) # Add the muted keyword input_field.send_keys(keyword) # Click the Save button save_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-testid='settingsDetailSave']"))) driver.execute_script("arguments[0].click();", save_button) # Use JavaScript click to avoid interception time.sleep(2) # Allow time for the save action to complete # Call the function for multiple keywords keywords = ["normal","with space","#withhash"] for keyword in keywords: add_muted_keyword(keyword) |
Notlar:
Script yarı manuel çalıştığı için tarayıcıyı açmanız gerekebilir.
sleep komutu kullanıldığından, internet hızınız yavaşsa hatalar oluşabilir. Gerekirse sleep sürelerini ayarlayın.
Bonus:
Kendi Twitter akış ekranımda, genellikle bahis siteleriyle ilgili olan kelimeler ekliyorum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
keywords = [ "Köfteci Yusuf", "Bunun ismini bilen", "NAKİT BONUSU", "Extra Bonusu", "DİSCOUNT VERİYORUZ", "Bonus Buy", "ÖZEL ORANLI", "Güvenilir Bahis", "Kazanmaya Başla", "BETPUBLIC", "Kayıp Bonusu", "Bahisin Kaybederse", "Çevrimsiz", "Harika kazançlar", "ikimisli", "anka", "Oğan", "Sinan Oğan", "Çevrimsiz Bonus", "EN YÜKSEK ORANLAR", "TL BONUS", "Free Spin", "Slot", "Ödül Havuzu", "Slot Rüzgarında", "Deneme Bonusu", "intobet", "Hoş Geldin Bonusu", "Yatırım Bonusu", "FreeBet", "PiaBellaCasino", "Bonusu Kaçırmayın", "ÇEKİLİŞ BİLETİ", "Aresbet'te", "Aresbet", "Survivor", "PozBet", "Freesbet", "Freespin", "wordle", "Free Bonus", "Casino", "çiftlik bank", "@ChangeTR", "@VodafoneTR", "@StarbucksTR", "VodafoneDestek" ] |