Skip to content
WJunction - Webmaster Forum

Need help with Python script (working with Wordpress posts)

Status
Not open for further replies.
Hi Folks!

I'm trying to write a nice little Python script that creates new Wordpress posts and should enter title, content, pick existing categories, enter tags and finally publish the post or save it as draft.

Now, I'm aware that a library exists (https://python-wordpress-xmlrpc.readthedocs.org/en/latest/) that does that thing with the use of the xmlrpc.php file. Since there have been numerous attacks hitting the Wordpress API, we are forced to turn off the API. That, however leaves my script naked in the rain and therefore I'm trying a different approach using Python Requests (Requests: HTTP for Humans — Requests 2.7.0 documentation) but since there's a whole bunch of AJAX going on and I have no clue how to work with AJAX websites I'm kind of stuck.

My code so far:
Code:
[COLOR=#00008B][FONT=Consolas]import[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] requests

[/FONT][/COLOR][COLOR=#00008B]with[/COLOR][COLOR=#000000] requests[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]Session[/COLOR][COLOR=#000000]() [/COLOR][COLOR=#00008B]as[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000]:[/COLOR][COLOR=#000000]
    login_url [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]'http://example.com/wp/wp-login.php'[/COLOR][COLOR=#000000]
    new_post_url [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]'http://example.com/wp/wp-admin/post-new.php'[/COLOR][COLOR=#000000]
    user [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]'user'[/COLOR][COLOR=#000000]
    pw [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]'password'[/COLOR][COLOR=#000000]
    params [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000]{[/COLOR][COLOR=#800000]'log'[/COLOR][COLOR=#000000]:[/COLOR][COLOR=#000000] user[/COLOR][COLOR=#000000], [/COLOR][COLOR=#800000]'pwd'[/COLOR][COLOR=#000000]:[/COLOR][COLOR=#000000] pw[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000]
    headers [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000]{[/COLOR][COLOR=#800000]'Referer'[/COLOR][COLOR=#000000]: [/COLOR][COLOR=#800000]'http://example.com/wp/wp-login.php'[/COLOR][COLOR=#000000], [/COLOR][COLOR=#800000]'Upgrade-Insecure-Requests'[/COLOR][COLOR=#000000]: [/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000]
    l [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]request[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]'POST'[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] login_url[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] data[/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000]params[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] allow_redirects[/COLOR][COLOR=#000000]=[/COLOR][COLOR=#00008B]True, [/COLOR][COLOR=#000000]headers[/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000]headers)
[/COLOR][COLOR=#000000]    np [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] c[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]request[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]'GET'[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] new_post_url[/COLOR][COLOR=#000000])[/COLOR]

Now, this code logs in to Wordpress and opens the "Create new post" page. I analysed the traffic a little bit but it seems there's one tiny bit of information I'm missing to process the whole data and get the requests to enter data like title, categories, etc. into the Wordpress post and publish it or save the draft.

I hope there are some Python/Wordpress/HTTP/AJAX/whatever cracks out there that like to help a guy out :)

Greetings
 
Status
Not open for further replies.

About the author

F
Active Member · Joined
96
Messages
34
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom