Record Python installation of wordpress_xmlrpc library to realize offline publishing of articles

These days, Lao Jiang has been studying Python crawler push articles to WordPress CMS. Here we generally use the xmlrpc.php protocol to push articles. Here, we need to install them to the wordpress_xmlrpc library. This is a simple way to sort out common online libraries and scripts for future study.

1. Install Library

 pip install python_wordpress_xmlrpc

You need to install the library here.

2. Demonstration script

 from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods import posts wp = Client(' https://domain.com/xmlrpc.php ', 'username', 'password') def post_new_article(title, content): post = WordPressPost() post.title = title post.content = content Post. post_status='draft' # Post status. If not written, it is draft by default. Private means private, draft means draft, and publish means release post.terms_names = { 'category': ['category directory'], 'post_tag': ['Tag1 ',' Tag2 '], } post.id = wp.call(posts. NewPost(post)) return post.id

Demonstration:

 # -*- coding: utf-8 -*- from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods import posts Username="Administrator User Name" Password="Administrator password" Apiurl="http://domain name/xmlrpc. php" # xmlrpc path of website wp = Client(apiurl, username, password,) print(wp) post = WordPressPost() Post. title='Article title 2' Post. content='Article content' Post. post_status='publish' # Post status. If it is not written, it is draft by default. Private means private, draft means draft, and publish means release post.terms_names = { 'post_tag': ['test ',' firstpost '], # The tag of the article. If there is no tag, it will be created automatically 'category': ['Introductions', 'Tests'] # The category of the article. If there is no category, it will be created automatically } post.id = wp.call(posts. NewPost(post)) print(post.id)
Vote for you

Source: Lao Jiang Tribe » Record Python installation of wordpress_xmlrpc library to realize offline publishing of articles |Welcome to share (public account: Chiang's circle of friends)

Get new information from webmaster/add QQ group from the public account "Chiang Kai shek's circle of friends"【 one billion twelve million four hundred and twenty-three thousand two hundred and seventy-nine 】Get preferential promotion from merchants