运用实现网站*敏*感*词*自动化发布文章源码:自动发布访问
优采云 发布时间: 2021-03-30 02:15运用实现网站*敏*感*词*自动化发布文章源码:自动发布访问
许多用来建立网站的朋友都遇到了这样的麻烦,网站已经建立,并且没有时间自己编写文章,并且它慢慢地被废弃了,有些朋友采集了很多喜欢的东西在其浏览器中的博客网站地址,因为采集的URL太多且太复杂,从那时起,我很少单击以打开它们。实际上,我们只需几行代码就可以充分利用和构建我们自己的文章抓取网站。它主要使用模块编写来实现Web爬虫。通过常规匹配对Web内容进行爬网后,它会自动发布到部署中网站。然后使用定时捕获。
#/usr/bin/env python
#coding=utf8
import httplib
import hashlib
import urllib
import random
import urllib2
import md5
import re
import json
import sys
import time
from lxml import html
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
from newspaper import Article
reload(sys)
sys.setdefaultencoding('utf-8')
time1 = time.time()
#得到html的源码
def gethtml(url1):
#伪装浏览器头部
headers = {
'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
}
req = urllib2.Request(
url = url1,
headers = headers
)
html = urllib2.urlopen(req).read()
return html
#得到目标url源码
code1 = gethtml('http://whuhan2013.github.io/archive/')
tree = html.fromstring(code1)
#print tree
targeturl=tree.xpath("//li[@class='listing-item']/a/@href")
def sends():
# print targeturl
for i in range(len(targeturl)):
#u=content1[i][0]
url="http://whuhan2013.github.io"+targeturl[i]
print url
a=Article(url,language='zh')
a.download()
a.parse()
#print a.text
dst=a.text
tag='test'
title=a.title
#print 'here2'
#链接WordPress,输入xmlrpc链接,后台账号密码
wp = Client('http://119.29.152.242/wordpress/xmlrpc.php','Ricardo','286840jjx')
#示例:wp = Client('http://www.python-cn.com/xmlrpc.php','username','password')
post = WordPressPost()
post.title = title
# post.post_type='test'
post.content = dst
post.post_status = 'publish'
#发送到WordPress
#print 'here3'
wp.call(NewPost(post))
time.sleep(3)
print 'posts updates'
if __name__=='__main__':
sends()
f1.close()
最后,您可以定期运行该程序,采集指定文章发送给
参考链接:用于实现网站*敏*感*词*自动发布文章
源代码:自动发布
访问:梁有业的博客
支持和代码突出显示,丰富的文章样式,文章交通插件等。
提供的博客插件
效果如下