Python 自动发博客脚本

以下是代码:

from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select
def blog():
    Browser=webdriver.Chrome()
    Browser.get("https://blog.csdn.net/Life666888")
    Browser.find_element_by_xpath("//*[@id=\"csdn-toolbar\"]/div/div/ul/li[5]/a[1]").click()
    Browser.find_element_by_xpath("/html/body/div[3]/div/div/div[2]/div/h3/a").click()
    time.sleep(2)
    Browser.find_element_by_xpath("//*[@id=\"username\"]").send_keys("账号")
    Browser.find_element_by_xpath("//*[@id=\"password\"]").send_keys("密码")
    Browser.find_element_by_xpath("//*[@id=\"fm1\"]/input[8]").click()
    time.sleep(2)
    Browser.find_element_by_xpath("//*[@id=\"csdn-toolbar\"]/div/div/ul/li[3]/a/span").click()
    Windos=Browser.window_handles
    Browser.switch_to_window(Windos[1])
    Browser.find_element_by_xpath("//*[@id=\"btnStart\"]").click()
    time.sleep(10)
    #Browser.execute_script("$('#txtTitle').val('我的Python自动化写博客脚本')")
    Browser.find_element_by_xpath("//input[@type=\"text\" and @id=\"txtTitle\"]").clear()
    time.sleep(1)
    Browser.find_element_by_xpath("//input[@type=\"text\" and @id=\"txtTitle\"]").send_keys("Python自动化写博客脚本")
    time.sleep(2)
    Browser.execute_script('document.getElementById("wmd-input").value="这是脚本发表的博客"')
    time.sleep(2)
    Browser.find_element_by_xpath("//*[@id=\"meditor_box\"]/div[1]/button").click()
    Browser.switch_to_default_content()
    selector=Select(Browser.find_element_by_xpath("//*[@id=\"selType\"]"))
    selector.select_by_value("original")
    time.sleep(2)
    #Browser.switch_to_default_content()
    selector1=Select(Browser.find_element_by_xpath("//select[@class=\"droBlogType\" and @id=\"radChl\"]"))
    selector1.select_by_value("28")
    time.sleep(2)
    Browser.find_element_by_xpath("//*[@id=\"meditor_box\"]/div[3]/div/div[6]/input[3]").click()
blog()

猜你喜欢

转载自blog.csdn.net/Life666888/article/details/81569370
今日推荐