Publish HTML data via XMLRPC in Python?

I am writing a small Python script to connect and publish content on my WordPress blog. It is pretty simple with https://github.com/maxcutler/python-wordpress-xmlrpc

However, when I tried to enter HTML data, for example:

<b>Hello</b> 

It appears exactly in the WordPress post (I watch it from a visual editor, and I need to reformat it by copying the data into HTML mode to get the expected result.

What should I do with my python script?

Thank you very much

+4
source share
1 answer

Can the HTML data you load already have angle brackets hidden in HTML objects? That is, <becomes <while> becomes & gt;

This will lead to the behavior you described. The visual editor will show what it looks like raw HTML, not the result of rendering HTML.

To fix it, either (i) prevent this encoding, or (ii) a quick and dirty approach, search and replace in HTML before passing your API. Sort of:

 html = html.replace('&lt;', '<') html = html.replace('&gt;', '>') 

gotta do the trick.

+1
source

Source: https://habr.com/ru/post/1333980/


All Articles