1

I'm trying to insert HTML content in my WordPress blog via XMLRPC but if i insert HTML - i got an error:

raise TypeError, "cannot marshal %s objects" % type(value) TypeError: cannot marshal objects

If i use bleach (for clean tags) - i got text with tags on my page

My code

# coding: utf-8
import requests
from bs4 import BeautifulSoup
import bleach
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods import posts


xmlrpc_url = "http://site.ru/xmlrpc.php"
wp_username = "user"
wp_password = "123"
blog_id = ""
client = Client(xmlrpc_url, wp_username, wp_password, blog_id)

url = "https://lifehacker.ru/2016/08/30/finansovye-sovety-dlya-molodyx-par/"
r = requests.get(url)
soup = BeautifulSoup(r.content)

post_title = soup.find("h1")
post_excerpt = soup.find("div", {"class", "single__excerpt"})
for tag in post_excerpt():
    for attribute in ["class", "id", "style"]: 
        del tag[attribute]
post_content = soup.find("div", {"class","post-content"})
for tag in post_content():
    for attribute in ["class", "id", "style"]:
        del tag[attribute]

post = WordPressPost()
post.title = post_title.text
post.content = post_content
post.id = client.call(posts.NewPost(post))

post.post_status = 'publish'
client.call(posts.EditPost(post.id, post))

How i can insert parsed HTML content in my WordPress blog?

1 Answer 1

1

Use .replace after bleach and fixed issue.

My code

...
post_content_insert = bleach.clean(post_content)

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


post = WordPressPost()
post.title = post_title.text
post.content = post_content_insert
post.id = client.call(posts.NewPost(post))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.