# -*- coding:utf-8 -*-
# pip install requests
# pip install lxml
# pip install wordpress-xmlrpc
import requests
from lxml import etree
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import NewPost
# 目标网站
url = 'http://www.mmjpg.com/'
# 请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
}
# 获取列表页
response = requests.get(url, headers=headers)
html = etree.HTML(response.text)
# 获取妹子列表
girl_list = html.xpath('//div[@class="pic"]/ul/li/a/@href')
# 连接wordpress
wp = Client('http://example.com/xmlrpc.php', 'your_username', 'your_password')
# 遍历妹子列表
for girl_url in girl_list:
# 获取妹子详情
response = requests.get(girl_url, headers=headers)
html = etree.HTML(response.text)
# 获取妹子图片
img_list = html.xpath('//div[@class="content"]/a/img/@src')
# 获取妹子标题
title = html.xpath('//div[@class="article"]/h2/text()')[0].replace('\n', '').replace(' ', '')
# 拼接图片标签
post_content = ''
for img in img_list:
post_content += '<img src="%s" alt="%s" />' % (img, title)
# 构建wordpress文章
post = WordPressPost()
post.title = title
post.content = post_content
post.post_status = 'publish'
# 发布文章
wp.call(NewPost(post))
爬妹子图并批量发布到wordpress
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《爬妹子图并批量发布到wordpress》
文章链接:https://www.gebizhan.com/1741.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
文章名称:《爬妹子图并批量发布到wordpress》
文章链接:https://www.gebizhan.com/1741.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。