Selenium自动写公众号文章
生活随笔
收集整理的這篇文章主要介紹了
Selenium自动写公众号文章
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天要在公眾號發幾百篇文章,感覺相當繁瑣,點了很長一段時間才發布30多個。這時我就想起了selenium。在網絡找了很久,沒發現相關源碼,實在沒辦法,只好自己動手。
try{SeleniumUtil.waitAppearAndClick(driver, 10, By.xpath("//div[@class='new-creation__menu-title']"));Thread.sleep(100);SeleniumUtil.switchToNextTag(driver);Thread.sleep(1000);driver.findElement(By.name("title")).sendKeys(title);driver.findElement(By.name("author")).sendKeys(author);WebDriver frame = driver.switchTo().frame(driver.findElement(By.id("ueditor_0")));frame.findElement(By.tagName("body")).sendKeys(content);driver.switchTo().defaultContent();SeleniumUtil.moveToThenClickAnother(driver,By.id("js_cover_area") ,By.xpath("//div[@id='js_cover_null']//a[text()='從圖片庫選擇']"));SeleniumUtil.waitAppearAndClick(driver,10,By.xpath("//div[@id='js_image_dialog_list_wrp']/div[@class='weui-desktop-img-picker__list']/div[@class='weui-desktop-img-picker__item']/i[1]"));SeleniumUtil.click(driver, driver.findElement(By.xpath("//button[text()='下一步']")));SeleniumUtil.waitAppearAndClick(driver, 10, By.xpath("//button[text()='完成']"));Thread.sleep(3000);driver.findElement(By.id("js_description")).sendKeys(des);SeleniumUtil.waitAppear(driver, 10, By.xpath("//div[@id='js_original']//input[@type='checkbox']"));SeleniumUtil.click(driver, driver.findElement(By.xpath("//div[@id='js_original']//input[@type='checkbox']")));SeleniumUtil.waitAppear(driver, 10, By.id("js_copyright_agree"));SeleniumUtil.makeSureCheckbox(driver, By.xpath("//input[@id='js_copyright_agree']"), 30);try{SeleniumUtil.waitAppear(driver, 3, By.xpath("//button[text()='下一步']"));SeleniumUtil.click(driver, driver.findElement(By.xpath("//button[text()='下一步']")));Thread.sleep(20);}catch(Exception ee){}SeleniumUtil.waitAppearAndClick(driver, 10,By.xpath("//div[@id='js_original_edit_box']//label[text()='文章類別']/../div[@class='weui-desktop-form__controls']/div[1]"));Thread.sleep(20);SeleniumUtil.click(driver, driver.findElement(By.xpath("//span[text()='星星物語']")));Thread.sleep(20);SeleniumUtil.click(driver, driver.findElement(By.xpath("//span[text()='牛郎']")));Thread.sleep(20);SeleniumUtil.click(driver, driver.findElement(By.xpath("//button[text()='確定']")));Thread.sleep(20);SeleniumUtil.moveToThenClickAnother(driver,By.xpath("//div[@class='js_appmsg_publish_wrp']/li[@class='icon_toggle_edit']/div[@class='border_of_js_publish']") ,By.id("js_publish_freely"));SeleniumUtil.waitAppear(driver, 10, By.xpath("//div[@class='weui-desktop-dialog']//button[text()='發布']"));SeleniumUtil.click(driver, driver.findElement(By.xpath("//button[text()='發布']")));SeleniumUtil.waitUntilUrlContain(driver, 100, "https://mp.weixin.qq.com/cgi-bin/home");SeleniumUtil.closeTag(driver);//發布成功的要刪掉System.out.println(title);FileUtil.del(path);}catch(Exception e){e.printStackTrace();}總結
以上是生活随笔為你收集整理的Selenium自动写公众号文章的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java加视频特效,实现伪原创
- 下一篇: 如何使用java程序操作ActiveMQ