我最终使用了WP-CLI 再加上一点重击来解决这个问题。
将所有post ID获取到文件中./wp-cli.phar post list --field=ID > posts.txt从每篇文章中生成HTML并将其放入单独的文件中cat posts.txt | while read line ; do ./wp-cli.phar post get $line --field=post_content > test/$line.html ; done使用PHP\'s DOMdocument 提取所有图像并生成WP-CLI命令
<?php
$start = "https://example.com/blog/";
foreach (glob("*.html") as $file) {
    if($file == \'.\' || $file == \'..\') continue;
    $id = substr($file, 0, -5);
    $html = file_get_contents($file);
    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $images = $doc->getElementsByTagName(\'img\');
    foreach($images as $img) {
       $imgSrc = $img->getAttribute(\'src\');
       $starter = substr( $imgSrc, 0, strlen($start) );
       if($starter == $start) {
          $imgLocation = substr( $imgSrc, strlen($start) );
          echo "./wp-cli.phar media import {$imgLocation} --post_id={$id} --skip-copy\\n";
       }
    }
}
 运行方式
commands.php > commands.txt运行文件中的所有WP-CLI命令
有点复杂,但它起作用了!