gpt4 book ai didi

php - 将 30,000 篇文章上传到 Wordpress 而不会导致 XML-RPC 崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:05 24 4
gpt4 key购买 nike

我有大约 30,000 个非常短的帖子要在 Wordpress 中发表。我使用 SQLlite 数据库和 python 脚本构建它们,并通过 python 中的 wordpress_xmlrpc 库上传它们。但是我的网站在 100-200 个帖子后就崩溃了,因为服务器认为这是一次 DoS 攻击。

我的服务器是一个 linux 机器,我可以通过 SSH 访问它。我正在寻找一种更直接轻松地将帖子上传到 Wordpress 的方法,比如通过直接与其数据库交互,或者使用直接在服务器上发生的本地进程。任何人都可以提供任何想法吗?

最佳答案

我尝试通过 Python 脚本直接与数据库交互来做同样的事情,它对我来说就像一个魅力。我使用的是 MySQL 数据库。

为此,您需要通过 ssh 连接到托管 Wordpress 站点和数据库的服务器。并在那里运行以下脚本:

Perquisite to run this script:

a. All the posts should be in different files within a single directory.

b. Each file should contain post title in first line and post content in rest of the lines.

#!/usr/bin/env python
import MySQLdb
import fnmatch
import os

#List to contain all the post files
my_match = []

#Gather post files in above list
for file in os.listdir("<path of the directory where post files remains>"):
if fnmatch.fnmatch(file, '.*'):
print(file)
continue
my_match.append(file)

print my_match

#Make database connection
conn = MySQLdb.connect(host= "localhost", user="<username>", passwd="<password>", db="<database name>")

x = conn.cursor()
print x

for fl in my_match:
new_file = "<path to the directory where post files remains>/" + fl
with open(new_file) as f:
heading = f.readline().strip()
content = f.read()


print heading
url = heading.replace(" ", "-")

print url

#try db query, change according to your database and tables
try:
x.execute("""INSERT INTO wp_posts (post_author, post_date, post_content, post_title, post_name) VALUES (3, "2017-03-28 20:24:12", %s, %s, %s)""",(content, heading, url))
conn.commit()
print "Done! :)"
except:
conn.rollback()
print "Oops, not done :("

conn.close()

关于php - 将 30,000 篇文章上传到 Wordpress 而不会导致 XML-RPC 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43520502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com