seeplusplus
Power Member
- Aug 18, 2008
- 525
- 179
Hi,
I need some help. I've written this code, which logs into Wordpress, goes to the 'add new post' page, inserts a post title, and then publishes it.
This works fine, the problem I'm having is entering the main content for the post.
Looking at the Wordpress page source, there is a "content" section, but when I try to add content to that, it doesn't work. The post title though does work, it has an ID of 'title'.
Has anyone any help they could offer me?
Here is the source, the GUI just has a webBrowser object and a button object.
Very simple, but I couldn't find the right element to enter the post's main content.
Thanks for any help.
I need some help. I've written this code, which logs into Wordpress, goes to the 'add new post' page, inserts a post title, and then publishes it.
This works fine, the problem I'm having is entering the main content for the post.
Looking at the Wordpress page source, there is a "content" section, but when I try to add content to that, it doesn't work. The post title though does work, it has an ID of 'title'.
Has anyone any help they could offer me?
Here is the source, the GUI just has a webBrowser object and a button object.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://localhost/wp/wordpress/wp-login.php");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.DocumentText.Contains("Remember Me"))
{
webBrowser1.Document.GetElementById("user_login").SetAttribute("value", "admin");
webBrowser1.Document.GetElementById("user_pass").SetAttribute("value", "password1");
webBrowser1.Document.GetElementById("wp-submit").InvokeMember("click");
}
else if (webBrowser1.DocumentText.Contains("Welcome to WordPress!"))
{
webBrowser1.Navigate("http://localhost/wp/wordpress/wp-admin/post-new.php");
}
else if (webBrowser1.DocumentText.Contains("Add New Post"))
{
webBrowser1.Document.GetElementById("title").SetAttribute("value", "my bots post title");
webBrowser1.Document.GetElementById("publish").InvokeMember("click");
}
else if (webBrowser1.DocumentText.Contains("Post published."))
{
MessageBox.Show("Post published");
}
else
{
MessageBox.Show("Should not hit");
}
}
Very simple, but I couldn't find the right element to enter the post's main content.
Thanks for any help.