python爬虫自动采集并上传更新网站 requests wordpress_xmlrpc wordpress实战

29 篇文章 0 订阅
9 篇文章 0 订阅

爬虫用的 bs4+requests

上传用的  wordpress_xmlrpc

#coded by 伊玛目的门徒
#coding=utf-8
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
import time
import requests
from bs4 import BeautifulSoup

header={'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.XXXX.XXX Safari/537.36'}

def getcontent():
    try:
        html=requests.get('https://futures.hexun.com/2019-12-17/199706366.html',headers=header)

        html.encoding='gbk'

        Soup = BeautifulSoup(html.text, "lxml")

        con=Soup.select('div.art_contextBox p')

        cont=''
        for y in con:
            #print (type(str(y)))
            cont=cont+str(y)

        print (cont)

        return (cont)

    except:
        pass


def wpsend(content):
    wp = Client('http://www.lianhanghao.xyz/xmlrpc.php', '***' '***')

    print (content)
    post = WordPressPost()
    post.title = '实例演示'
    post.content = " ''' "+ content +" ''' "

    post.post_status = 'publish'
    post.terms_names = {
       'post_tag': ['test'],
      'category': [ 'Tests']
    }
    wp.call(NewPost(post))
    localtime = time.localtime(time.time())
    print ('文档已上传 {}'.format(time.strftime("%Y-%m-%d %H:%M:%S",localtime)))



wpsend(getcontent())

网站在 http://www.lianhanghao.xyz/tests/317362

演示视频: https://www.bilibili.com/video/av80056985/

python爬虫自动采集并上传更新网站

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值