Use Python+Selenium+PhantomJS to automatically send tumblr

I feel that tumblr and I are at odds with each other, there are pits everywhere, and I have been irritable for a day. . .

There are mainly 2 problems:

1. When selecting input image text information, the css__selector address and xpath address directly copied from the browser development mode cannot be used.

Because the class attribute has spaces, the relative address of css_selector does not work, it must be the relative address of xpath:

driver.find_element_by_xpath('//*[@class="editor editor-richtext"]').send_keys(alt)

2. After the successful debugging of selenium+chrome locally, PhantomJS on the vps fails, the picture description text cannot be entered, and the prompt element is invisible. Just click on the blank first.

driver.find_element_by_xpath('//body').click()
def update_post(alt,src,tags):
    print('start')
    driver = webdriver.PhantomJS("/root/phantomjs")
    driver.get("http://www.tumblr.com/login")
    #Log in
    driver.find_element_by_id("signup_determine_email").send_keys("账号")
    driver.find_element_by_css_selector(".signup_determine_btn").click()
    sleep(1)
    driver.find_element_by_id("signup_password").send_keys("密码")
    driver.find_element_by_css_selector(".signup_login_btn").click()
    #click to post image
    driver.find_element_by_xpath('//i[@class="icon_post_photo"]').click()
    sleep(1)
    #Click on the network picture
    driver.find_element_by_xpath('//div[@class="dropzone-icon dropzone-add-url-icon"]').click()
    sleep(1)
    driver.find_element_by_css_selector('.editor-plaintext').send_keys(src)
    driver.find_element_by_css_selector('.editor-plaintext').send_keys(Keys.ENTER)
    sleep(3)
    # send text
    driver.find_element_by_xpath('//body').click()
    driver.find_element_by_xpath('//*[@class="editor editor-richtext"]').click()
    driver.find_element_by_xpath('//*[@class="editor editor-richtext"]').send_keys(alt)
    #send tags
    for tag in tags:
        driver.find_element_by_xpath('//*[@aria-label="post label"]').click()
        driver.find_element_by_xpath('//*[@aria-label="post label"]').send_keys('#')
        driver.find_element_by_xpath('//*[@aria-label="post label"]').send_keys(tag)
        driver.find_element_by_xpath('//*[@aria-label="帖子标签"]').send_keys(Keys.ENTER)
    #submit
    driver.find_element_by_xpath('//button[@class="button-area create_post_button"]').click()
    sleep(1)
    driver.quit()
    print('post updating success')

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325391825&siteId=291194637