Last active
October 30, 2021 13:26
-
-
Save mostafa1972/ddddccb23625ccc1763562ea93d2e7e6 to your computer and use it in GitHub Desktop.
Auto Message to FB Group by Selenium Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
def main(): | |
# Your Facebook account user and password | |
usr = str(input("Enter User Email ID:")) | |
pwd = str(input("Enter User Password:")) | |
message = "Auto FB Group Message through Selenium Bot." | |
#set multiple fb groups here | |
group_links = [ | |
"https://web.facebook.com/groups/python.eshikhon","https://web.facebook.com/messages/t/2613328745398719" | |
] | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_experimental_option("detach", True) | |
chrome_options.add_argument("--disable-infobars") | |
chrome_options.add_experimental_option("prefs", { \ | |
"profile.default_content_setting_values.notifications": 2 # 1:allow, 2:block | |
}) | |
driver = webdriver.Chrome(executable_path="driver/chromedriver") | |
driver.implicitly_wait(5) # seconds | |
# Go to facebook.com | |
driver.get("http://www.facebook.com") | |
# Enter user email | |
elem = driver.find_element_by_id("email") | |
elem.send_keys(usr) | |
# Enter user password | |
elem = driver.find_element_by_id("pass") | |
elem.send_keys(pwd) | |
# Login | |
elem.send_keys(Keys.RETURN) | |
for group in group_links: | |
# Go to the Facebook Group | |
driver.get(group) | |
# Click the post box | |
post_box=driver.find_element_by_xpath("//*[@name='xhpc_message_text']") | |
# Enter the text we want to post to Facebook | |
post_box.send_keys(message) | |
sleep(5) | |
buttons = driver.find_elements_by_tag_name("button") | |
sleep(5) | |
for button in buttons: | |
if button.text == "Post": | |
button.click() | |
sleep(10) | |
print("post done") | |
driver.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
post_box=driver.find_element_by_xpath("//*[@name='xhpc_message_text']") me sale error alguna solucion ?