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();
			}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ak01_10

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值