Sign in to follow this  
Followers 0
dfobare

Trying to script WordPress

11 posts in this topic

I'm trying to build a script that logs into WP and starts a post. I'm able to log in, click on "Write" to start a new post. But everything I try to do from there is a failure. I can't seem to get ahold of the posting form, or the textarea that holds the content. I've tried clicking on "HTML" as an alternative but can't do that either. Has anyone here written an autoposter before?

Share this post


Link to post
Share on other sites



I'm trying to build a script that logs into WP and starts a post. I'm able to log in, click on "Write" to start a new post. But everything I try to do from there is a failure. I can't seem to get ahold of the posting form, or the textarea that holds the content. I've tried clicking on "HTML" as an alternative but can't do that either. Has anyone here written an autoposter before?

Since you're using Wordpress, I know that one option available (when using your own Wordpress installation, unsure if the same option is available with a Wordpress.com "hosted" account) is to create an email account for posts.

e.g., Send an email to wordpresscustomemail@yourdomain.com that will generate a post based upon the email contents (I believe subject line = post title, and the message body = the post body content).


- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Ok, I guess I'll post my code on this. Here is the segment that works:

;
#include <IE.au3>
$oIE = _IECreate ("www.thisismyblog.com/blog/wp-admin")
Sleep(1000)
$oForm = _IEFormGetObjByName ($oIE, "loginform")

$oQuery = _IEFormElementGetObjByName ($oForm, "log")
_IEFormElementSetValue ($oQuery, "admin")

$oQuery2 = _IEFormElementGetObjByName ($oForm, "pwd")
_IEFormElementSetValue ($oQuery2, "mypassword")

_IEFormSubmit ($oForm, 0)
_IELoadWait($oIE)

_IELinkClickByText ($oIE, "Write")
_IELoadWait($oIE)

Sleep(1000)

Standard stuff; as an inexperienced AU coder this was pretty quick and easy to write. Here comes the code that doesn't:

$oTextForm = _IEFormGetObjByName ($oIE, "post")
$oQuery3 = _IEFormElementGetObjByName ($oTextForm, "content")
_IEFormElementSetValue ($oQuery3, "this is a test")

From reading the docs I get there might be a problem with the above thanks to Javascript onclick handlers. I've tried the alternatives but had no luck. Can anyone point the way?

Share this post


Link to post
Share on other sites

Monamo: thx for the reply. I was working mine the same time you were working on yours, so I didn't see it. Sorry.

My goal with this script is to run a server-side PHP script that produces some automated content based on a mysql query, scrape the screen for the results, then log in to WP, start a new post, then dump the PHP output into the textarea. The script ends there, as I then manually add a couple of sentences or paragraphs commentary before clicking the Publish button.

That's the direct route. I considered the email idea. Basically after scraping the browser for the PHP results, I email them to my WP, then open up WP itself, and choose to edit the post I just set up thru the email. This brings up a couple of considerations:

1) I've heard that enabling WP posting via email is a bit of a security hole. Probably not a big deal though.

2) I'd like the posting email to have WP set up a new post with it, but not actually publish. That can probably be done; I need to look at the WP docs more thoroughly.

3) Assuming #2 is successfully completed, I still have to get AutoIt to focus on the textarea that holds the emailed post once I navigate to the Edit screen. Since I can't yet do that on the Write page, I can't imagine I'd be able to do that on the Edit page.

Still, this is something I'm going to explore.

Dave

Since you're using Wordpress, I know that one option available (when using your own Wordpress installation, unsure if the same option is available with a Wordpress.com "hosted" account) is to create an email account for posts.

e.g., Send an email to wordpresscustomemail@yourdomain.com that will generate a post based upon the email contents (I believe subject line = post title, and the message body = the post body content).

Share this post


Link to post
Share on other sites

1) I've heard that enabling WP posting via email is a bit of a security hole. Probably not a big deal though.

The only concern I'm aware of outright is that if someone else knows the email address, they could post to your site. That being said, I have always just used a random password generator to create a "password" that I use as the account name. I've never had any fictitious posts created with this method, though if it occurred, it would be a two-minute fix to generate a new account and update my Wordpress configs accordingly.

As for posting, but not publishing, sadly I haven't got a clue on a direction to point ya there.


- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

So then you use just the email facility, yes?

Here is a weird thing: today I got this script to work just fine on my work machine, but it fails on my home machine. Here is the total script:

#include <IE.au3>
#include <file.au3>

$oIE = _IECreate ("www.thisismysite.com/RecentSubmissions.php")
$sHTML = _IEBodyReadHTML ($oIE)
_IELoadWait($oIE)

_IENavigate ($oIE,"www.thisismysite.com/blog/wp-admin")
_IELoadWait($oIE)

Sleep(1000)
$oForm = _IEFormGetObjByName ($oIE, "loginform")

$oQuery = _IEFormElementGetObjByName ($oForm, "log")
_IEFormElementSetValue ($oQuery, "admin")

$oQuery2 = _IEFormElementGetObjByName ($oForm, "pwd")
_IEFormElementSetValue ($oQuery2, "mypwd")

_IEFormSubmit ($oForm, 0)
_IELoadWait($oIE)

_IELinkClickByText ($oIE, "Write")
_IELoadWait($oIE)

Sleep(1000)


$oTextForm = _IEFormGetObjByName ($oIE, "post")
$oQuery3 = _IEFormElementGetObjByName ($oTextForm, "content")
_IEFormElementSetValue ($oQuery3, $sHTML)

On IE7 at work this is going just fine. But here at home on IE7 where I really need to use this, the script stops gracefully after click on "Write".

Any ideas?

As for posting, but not publishing, sadly I haven't got a clue on a direction to point ya there.

Share this post


Link to post
Share on other sites

I ought to note that I have tried alternative UDF's like _IEFormGetCollection and _IEFormElementGetCollection and they have failed as well.

If you're reading this, is there any other info I need to provide to enlist your help?

Share this post


Link to post
Share on other sites

I should also note a couple of other strange behaviors. First I can post to the Title field just fine - IF I use a $oQuery3 = _IEFormElementGetObjByName ($oTextForm, "title") command. I mention this because the name of the Title field is really "post-title". But if I use "post-title" instead of "title", the code doesn't work.

I find it curious that the "id" attribute of this INPUT to be "title". As though the _IEFormElementGetObjByName UDF is really grabbing by "id" and not "name".

Of course, this doesn't help with the textarea; its id and name attributes are both 'content'. I wonder if the fact that those attributes on the textarea are encased by single quotes and not double makes a difference.

Share this post


Link to post
Share on other sites

Ok, now I'm frosted. I decided to try a _IETagNameGetCollection($oIE, "textarea") to grab the form's textareas and loop thru the collection and do a IEFormElementSetValue on the one named 'content'. I used a msgBox call to verify that I got it, and indeed I did. But the IEFormElementSetValue still didn't deposit any text.

BUT I also tried stuffing some text into one of the other textareas available when making a post to WP: the "excerpt" box. Its a ways down the page. And that textarea is stuffed just fine by a IEFormElementSetValue call. But not the all important 'content' textarea.

I'm stumped.

Share this post


Link to post
Share on other sites

Your code doesn't get me to the blog page, so I cannot see what you see.

One very common mistake in these types of systems is that what looks like a text are is not, but is rather an iFrame that looks like one. If that is the case, you need to get a reference to the frame with _IEFrameGet* and then use _IEBodyWriteHTML

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0