Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. # coding: utf-8
  2. import requests
  3. from bs4 import BeautifulSoup
  4. import bleach
  5. from wordpress_xmlrpc import Client, WordPressPost
  6. from wordpress_xmlrpc.methods import posts
  7.  
  8.  
  9. xmlrpc_url = "http://site.ru/xmlrpc.php"
  10. wp_username = "user"
  11. wp_password = "123"
  12. blog_id = ""
  13. client = Client(xmlrpc_url, wp_username, wp_password, blog_id)
  14.  
  15. url = "https://lifehacker.ru/2016/08/30/finansovye-sovety-dlya-molodyx-par/"
  16. r = requests.get(url)
  17. soup = BeautifulSoup(r.content)
  18.  
  19. post_title = soup.find("h1")
  20. post_excerpt = soup.find("div", {"class", "single__excerpt"})
  21. for tag in post_excerpt():
  22. for attribute in ["class", "id", "style"]:
  23. del tag[attribute]
  24. post_content = soup.find("div", {"class","post-content"})
  25. for tag in post_content():
  26. for attribute in ["class", "id", "style"]:
  27. del tag[attribute]
  28.  
  29. post = WordPressPost()
  30. post.title = post_title.text
  31. post.content = post_content
  32. post.id = client.call(posts.NewPost(post))
  33.  
  34. post.post_status = 'publish'
  35. client.call(posts.EditPost(post.id, post))
  36.  
  37. ...
  38. post_content_insert = bleach.clean(post_content)
  39.  
  40. post_content_insert = post_content_insert.replace('<','<')
  41. post_content_insert = post_content_insert.replace('>','>')
  42.  
  43.  
  44. post = WordPressPost()
  45. post.title = post_title.text
  46. post.content = post_content_insert
  47. post.id = client.call(posts.NewPost(post))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement