python scrapy 表单post rest api接口返回json写wordpress

import scrapy
import json
from urllib.parse import urlencode
from scrapy.crawler import CrawlerProcess
from scrapy import Spider, FormRequest
from wordpress_xmlrpc import Client, wordpressPost
from wordpress_xmlrpc.methods.posts import NewPost

id = 'username'
password	= 'pwd'
publish_url = 'http://wordpress.url/xmlrpc.PHP'
source_url	= 'http://gubatopic.eastmoney.com/interface/GetData.aspx'
post_data	={"param": "ps%3D7%26p%3D1%26type%3D0","path":"newtopic%2Fapi%2FTopic%2FHomePagelistRead","env":"2"}

class EmSpider(Spider):
    name = "em"
    def start_requests(self):
        yield FormRequest(source_url, formdata=post_data)

    def parse(self,response):
        for item in json.loads(response.text)['re']:
            print(item['nickname']+' ,'+str(item['htid']))
            wp = Client(publish_url, id, password)
            post = wordpressPost()
            post.post_status = 'publish'
            post.title = item['nickname']
            post.content = str(item['htid'])
            #post.excerpt = '这里是摘抄样式示例'
            post.terms_names = {
            	"post_tag": ['Python'],
            	"category": ['Python']
            }
            wp.call(NewPost(post))				

  

相关文章

我们有时候在定制WORDPRESS主题的时候,由于菜单样式的要求我...
很多朋友在做wordpree主题制作的时候会经常遇到一个问题,那...
wordpress后台的模块很多,但并不是每个都经常用到。介绍几段...
从WordPress4.2版本开始,如果我们在MYSQL5.1版本数据中导出...
很多网友会遇到这样一个问题,就是WordPress网站上传图片、附...
对于经常要在文章中出现代码的IT相关博客,安装一个代码高亮...