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

2022/1/5 22:34:28

本文主要是介绍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))				

  



这篇关于python scrapy 表单post rest api接口返回json写wordpress的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程