如何使用 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] 删除。
我来说两句