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))