如何使用 Python 和 selenium 自动发布 Facebook 状态(在新布局之后)

阿都沙末 |

Facebook 图像及其 xpath

如何使用 python 和 selenium 在新的 Facebook 布局后自动发布我的状态......?在此更新之前,我有一个完美的执行,但现在它说 Xpath 未找到,也没有使用 css 或 tag 属性找到

这是我访问此字段的代码

for line in obj2:
    #timeline
    driver.find_element_by_xpath(".//*[@id='js_9a']/div[1]/div/div[1]/div[2]/div/div/div/div/div/div[2]/div/div/div/div").send_keys(line)  

    #post button
    driver.find_element_by_xpath(".//[@id='js_9a']/div[2]/div[3]/div/div[2]/div/div[2]/button").click() 
奥斯卡·马丁内斯

这应该解决该任务。(如果我找到更好的方法,我会编辑代码)

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

import time
### login details ########################
username = "[email protected]"
pwd = "xxxxxxxxx"
##########################################

### what is on my mind ###################
msg = "hey there!"
##########################################

# initializing driver and loading web
chrome_path = r"chromedriver.exe"
options = Options()
options.add_argument("--disable-notifications")
driver = webdriver.Chrome(chrome_path, chrome_options=options)
driver.get("http://www.facebook.com/")
# end initializing

# start login
user_input = driver.find_element_by_xpath("""//*[@id="email"]""")
pwd_input = driver.find_element_by_xpath("""//*[@id="pass"]""")
user_input.send_keys(username)
pwd_input.send_keys(pwd)
pwd_input.send_keys(Keys.ENTER)
# end login

# writing msg
time.sleep(3)
first_what_is_on_my_mind_element = driver.find_element_by_class_name("_5qtp")
first_what_is_on_my_mind_element.click()
time.sleep(3)
second_what_is_on_my_mind_element = driver.switch_to.active_element
second_what_is_on_my_mind_element.send_keys(msg)
# end writing

# posting
buttons = driver.find_elements_by_tag_name('button')
for button in buttons:
    if 'Post' in button.text:
        button.click()
# end posting

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用 Selenium 和 Python 自动点击“接受 cookie”按钮

使用 selenium 和 python 自动登录,如何正确提取用户和密码元素

如何使用python在Facebook墙上发布消息

使用Pagetab应用自动在Facebook上发布

使用Selenium Webdriver自动执行Facebook登录

使用 selenium 和 python 自动化 WhatsApp

使用 selenium 和 python 实现网站自动化

如何使用Selenium和Python从自动建议中选择一个选项

如何使用Selenium和Python在Firefox中禁用自动完成功能?

如何使用Python和Selenium自动登录据说不可见的元素?

如何使用Selenium和Python单击链接

如何使用Selenium和Python上传文件

如何使用Selenium和Python抓取注释?

如何使用Selenium和Python识别元素

如何使用 selenium webdriver 和 python 等待并获取 web 元素的状态

Selenium和Python使用If语句

使用 Selenium (Python) 自动登录

如何使用 python 和 selenium 在新选项卡中打开链接

无法在Twitter和Facebook中使用社交身份验证发布状态

使用 Selenium 从 Facebook 获取照片的喜欢和评论

使用 python facebook sdk 在 facebook 上发布更新/消息

Android:如何在Facebook上发布状态

在Selenium和Python自动填充默认文本之前,如何填充javascript小部件

需要帮助使用 Selenium-Chromedriver 和 Python3,浏览器自动化

尝试使用 selenium 和 python 自动填充数据表单

希望使用Python和Selenium自动化卖家登录门户,找到xPath

使用 selenium (Python) 实现 Instagram 自动化 - 关注和取消关注按钮

使用 python 和 selenium 实现自动化 - 每次访问时都会更改框架名称

如何使用facebook-sdk python在im成员的facebook组中发布