Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,61 +52,64 @@ setuptools.setup(
|
|
| 52 |
)
|
| 53 |
|
| 54 |
def main():
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
# Set up text content to post
|
| 65 |
-
message = "Checkout an amazing selenium script for posting automaticaaly on Facebook groups! https://github.com/ethanXWL/Python-Selenium-Facebook-group-poster"
|
| 66 |
|
| 67 |
-
# Set up paths of images to post
|
| 68 |
-
images_list = ['C:/Users/OEM/Pictures/sample1.jpg','C:/Users/OEM/Pictures/sample2.jpg']
|
| 69 |
|
| 70 |
# Login Facebook
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
if __name__ == '__main__':
|
| 112 |
main()
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
def main():
|
| 55 |
+
# Input fields
|
| 56 |
+
st.title("Facebook Group Poster")
|
| 57 |
+
account = st.text_input("Facebook Account Email", "sample@gmail.com")
|
| 58 |
+
password = st.text_input("Facebook Password", "sample", type="password")
|
| 59 |
+
groups_links_list = st.text_area("Facebook Group URLs (one per line)",
|
| 60 |
+
"https://www.facebook.com/groups/sample1\nhttps://www.facebook.com/groups/sample2")
|
| 61 |
+
message = st.text_area("Post Message", "Checkout this amazing script...")
|
| 62 |
+
images_list = st.file_uploader("Upload Images", accept_multiple_files=True)
|
| 63 |
|
| 64 |
+
if st.button('Post to Facebook Groups'):
|
| 65 |
+
# Only execute if the button is clicked
|
| 66 |
+
if not account or not password or not groups_links_list or not message or not images_list:
|
| 67 |
+
st.error("Please fill all the fields.")
|
| 68 |
+
else:
|
| 69 |
+
|
| 70 |
|
|
|
|
|
|
|
| 71 |
|
|
|
|
|
|
|
| 72 |
|
| 73 |
# Login Facebook
|
| 74 |
+
chrome_options = Options() # Use the Options class
|
| 75 |
+
prefs = {"profile.default_content_setting_values.notifications" : 2}
|
| 76 |
+
chrome_options.add_experimental_option("prefs", prefs)
|
| 77 |
+
driver = webdriver.Chrome(options=chrome_options) # Pass 'options'
|
| 78 |
+
driver.get('https://www.facebook.com')
|
| 79 |
+
emailelement = driver.find_element(By.XPATH,'//*[@id="email"]')
|
| 80 |
+
emailelement.send_keys(account)
|
| 81 |
+
passelement = driver.find_element(By.XPATH,'//*[@id="pass"]')
|
| 82 |
+
passelement.send_keys(password)
|
| 83 |
+
loginelement = driver.find_element(By.XPATH,'//*[@id="loginbutton"]')
|
| 84 |
+
loginelement.click()
|
| 85 |
+
|
| 86 |
+
# Post on each group
|
| 87 |
+
for group in groups_links_list:
|
| 88 |
+
driver.get(group)
|
| 89 |
+
time.sleep(2)
|
| 90 |
+
try:
|
| 91 |
+
driver.find_element(By.XPATH,'//*[@label="Start Discussion"]').click()
|
| 92 |
+
post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
| 93 |
+
except:
|
| 94 |
+
post_box=driver.find_element_by_css_selector("[name='xhpc_message_text']")
|
| 95 |
+
post_box.send_keys(message)
|
| 96 |
+
time.sleep(1)
|
| 97 |
+
for photo in images_list:
|
| 98 |
+
photo_element = driver.find_element(By.XPATH,'//input[@type="file"]')
|
| 99 |
+
photo_element.send_keys(photo)
|
| 100 |
+
time.sleep(1)
|
| 101 |
+
time.sleep(6)
|
| 102 |
+
post_button = driver.find_element_by_xpath("//*[@data-testid='react-composer-post-button']")
|
| 103 |
+
clickable = False
|
| 104 |
+
while not clickable:
|
| 105 |
+
cursor = post_button.find_element_by_tag_name('span').value_of_css_property("cursor")
|
| 106 |
+
if cursor == "pointer":
|
| 107 |
+
clickable = True
|
| 108 |
+
break
|
| 109 |
+
post_button.click()
|
| 110 |
+
time.sleep(5)
|
| 111 |
+
# Close driver
|
| 112 |
+
driver.close()
|
| 113 |
|
| 114 |
if __name__ == '__main__':
|
| 115 |
main()
|