美文网首页
Mac环境selenium 自动发表twitter 文章

Mac环境selenium 自动发表twitter 文章

作者: 搁浅的三刀流zoro | 来源:发表于2019-07-15 10:51 被阅读0次

    pip install selenium

    安装chrome driver(参考https://blog.csdn.net/zxy987872674/article/details/53082896)

    ```

    from selenium import webdriver

    from selenium.webdriver.common.by import By

    import time

    driver = webdriver.Chrome()

    driver.get("https://twitter.com")

    loginBtn  = (By.XPATH,'//*[@id="doc"]/div/div[1]/div[1]/div[2]/div[2]/div/a[2]')

    driver.find_element(*loginBtn).click()

    time.sleep(3)

    driver.implicitly_wait(3)

    phone_input = (By.XPATH,'//*[@id="page-container"]/div/div[1]/form/fieldset/div[1]/input')

    //请替换用户名密码

    driver.find_element(*phone_input).send_keys('name')

    pwd_input = (By.XPATH,'//*[@id="page-container"]/div/div[1]/form/fieldset/div[2]/input')

    driver.find_element(*pwd_input).send_keys('pwd')

    loginBtn2 = (By.XPATH,'//*[@id="page-container"]/div/div[1]/form/div[2]/button')

    driver.find_element(*loginBtn2).click()

    time.sleep(2)

    driver.implicitly_wait(2)

    happenning = (By.XPATH,'//*[@id="tweet-box-home-timeline"]')

    driver.find_element(*happenning).click()

    time.sleep(1)

    driver.implicitly_wait(1)

    driver.find_element(*happenning).send_keys('for test')

    time.sleep(1)

    driver.implicitly_wait(1)

    tweet = (By.XPATH,'//*[@id="timeline"]/div[2]/div/form/div[3]/div[2]/button')

    driver.find_element(*tweet).click()

    ```


    获取控件元素路径(使用Google浏览器)

    相关文章

      网友评论

          本文标题:Mac环境selenium 自动发表twitter 文章

          本文链接:https://www.haomeiwen.com/subject/vadopftx.html