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

      

  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/meetrice/p/15769014.html
Copyright © 2020-2023  润新知