Is it possible to export wordpress article to .txt?

Jimm22

Registered Member
Joined
Jul 15, 2021
Messages
73
Reaction score
51
I want to export the articles on my website to .txt but I can't find a plugin for this. Every export plugin allow you to export in csv and other formats but not txt.

Any idea what should I do?
 
And what kind of format do you expect your txt file to be in? How do you store tags, categories, author, date times, and other meta data associated with each post?

What is it exactly you are trying to save to txt? WP converts the content in the editor to html so even if you export just the content in each page you will still end up with html. Pandoc will allow you to convert this markup to any other markup.

You could use the WP rest API, example.com/wp-json/wp/v2/posts to fetch your WP content as a JSON object, then iterate the results, and save the post content to the post-slug-as-the-filename.txt as the filename.
 
I want to export the articles on my website to .txt but I can't find a plugin for this. Every export plugin allow you to export in csv and other formats but not txt.

Any idea what should I do?
the articles are in your wordpress sql database. if you want, you can export the database to get the content, or just code a simple php script to output the wordpress arrticles as you need
 
And what kind of format do you expect your txt file to be in? How do you store tags, categories, author, date times, and other meta data associated with each post?

What is it exactly you are trying to save to txt? WP converts the content in the editor to html so even if you export just the content in each page you will still end up with html. Pandoc will allow you to convert this markup to any other markup.

You could use the WP rest API, example.com/wp-json/wp/v2/posts to fetch your WP content as a JSON object, then iterate the results, and save the post content to the post-slug-as-the-filename.txt as the filename.
I don't need categories and such, I only need to store the title (possibly as the name of the file) and the content of the article. If html is stored is even better since I will throw those articles on RankerX, so those articles will be published on 2.0s and similar.
 
I think you can use Export function in Wordpress, and after that, all texts are there, maybe you need some customized tool to extract it.

Well, just copy and paste, don't be lazy, even thousands posts, just several days work.
 
I don't need categories and such, I only need to store the title (possibly as the name of the file) and the content of the article. If html is stored is even better since I will throw those articles on RankerX, so those articles will be published on 2.0s and similar.

When you export out of WordPress you need a structure to store the content and all of the meta data around it and CSV, JSON make for an easy structure to export and then import it. The .csv and .json extensions tell an application what structure the data is in. At the end of the day csv and json are simple text files that can be opened with a text editor, but a plain text file is not a structure, you would build your own structure and put it into a text file. Makes sense?

Your project needs here are pretty specific to your own use case which is why you might have difficulty finding a plugin to do what you want. You can see if this plugin gets you what you want. They also have a PDF version.

If it were me I would script this. It's an easy enough project for any novice PHP'er to do. You can query your WP database directly ( you might need to open port 3306 to access the db locally), or use the WP rest API to page through your posts.
 
here is a simple example that i just made to save/print all titles + posts from wp.
just modify it for your needs :)

Code:
<?php
   /* quick example script to save (or print) all titles + posts from wordpress
    * (C) styx @ argo-content.com
    */

   define('USER', 'wpusr'); // mysql user
   define('PASS', 'wppass'); // mysql pass
   define('DB', 'wpdb'); // database name
   define('DBHOST', 'localhost'); // database host
   define('SFX', 'wp'); // WP db suffix ('wp' by default)

   function connect_db() {
      $mysql = new mysqli(DBHOST,USER,PASS,DB);
      if(mysqli_connect_errno()) {
         printf("Error - database connection failed: %s", mysqli_connect_error());
         die();
      }
      return $mysql;
   }

   function static_query($query, $mysql) {
      if(!$st=$mysql->query($query)) {
         die('error: '.$mysql->error."\n");
      }
      return $st;
   }

   function get_posts($mysql) {
      $rw=NULL;
      $st = static_query('SELECT post_title,post_content FROM '.SFX.'_posts', $mysql);
      while($rw=$st->fetch_assoc()) {
         $arr[] = array($rw['post_title'], strip_tags($rw['post_content']));
      }
      return $arr;
   }

   $mysql = connect_db();
   $posts = get_posts($mysql);
   foreach ($posts as $p) {
      // print('title: '.$p[0]."\n".'post: '.$p[1]."\n --- \n");
      $fl = str_replace(' ', '-', $p[0]).'.txt';
      file_put_contents($fl, $p[1]);
   }
?>
 
Can be done through a database query. Give a link to the site
 
Easy

Python can handle this, either requests or selenium
 
@itz_styx script should do what you need, but if you're scraping content from other's sites - you'd need something else.
 
here is a simple example that i just made to save/print all titles + posts from wp.
just modify it for your needs :)

Code:
<?php
   /* quick example script to save (or print) all titles + posts from wordpress
    * (C) styx @ argo-content.com
    */

   define('USER', 'wpusr'); // mysql user
   define('PASS', 'wppass'); // mysql pass
   define('DB', 'wpdb'); // database name
   define('DBHOST', 'localhost'); // database host
   define('SFX', 'wp'); // WP db suffix ('wp' by default)

   function connect_db() {
      $mysql = new mysqli(DBHOST,USER,PASS,DB);
      if(mysqli_connect_errno()) {
         printf("Error - database connection failed: %s", mysqli_connect_error());
         die();
      }
      return $mysql;
   }

   function static_query($query, $mysql) {
      if(!$st=$mysql->query($query)) {
         die('error: '.$mysql->error."\n");
      }
      return $st;
   }

   function get_posts($mysql) {
      $rw=NULL;
      $st = static_query('SELECT post_title,post_content FROM '.SFX.'_posts', $mysql);
      while($rw=$st->fetch_assoc()) {
         $arr[] = array($rw['post_title'], strip_tags($rw['post_content']));
      }
      return $arr;
   }

   $mysql = connect_db();
   $posts = get_posts($mysql);
   foreach ($posts as $p) {
      // print('title: '.$p[0]."\n".'post: '.$p[1]."\n --- \n");
      $fl = str_replace(' ', '-', $p[0]).'.txt';
      file_put_contents($fl, $p[1]);
   }
?>
THANK YOU VERY MUCH!!!!
 
here is a simple example that i just made to save/print all titles + posts from wp.
just modify it for your needs :)

Code:
<?php
   /* quick example script to save (or print) all titles + posts from wordpress
    * (C) styx @ argo-content.com
    */

   define('USER', 'wpusr'); // mysql user
   define('PASS', 'wppass'); // mysql pass
   define('DB', 'wpdb'); // database name
   define('DBHOST', 'localhost'); // database host
   define('SFX', 'wp'); // WP db suffix ('wp' by default)

   function connect_db() {
      $mysql = new mysqli(DBHOST,USER,PASS,DB);
      if(mysqli_connect_errno()) {
         printf("Error - database connection failed: %s", mysqli_connect_error());
         die();
      }
      return $mysql;
   }

   function static_query($query, $mysql) {
      if(!$st=$mysql->query($query)) {
         die('error: '.$mysql->error."\n");
      }
      return $st;
   }

   function get_posts($mysql) {
      $rw=NULL;
      $st = static_query('SELECT post_title,post_content FROM '.SFX.'_posts', $mysql);
      while($rw=$st->fetch_assoc()) {
         $arr[] = array($rw['post_title'], strip_tags($rw['post_content']));
      }
      return $arr;
   }

   $mysql = connect_db();
   $posts = get_posts($mysql);
   foreach ($posts as $p) {
      // print('title: '.$p[0]."\n".'post: '.$p[1]."\n --- \n");
      $fl = str_replace(' ', '-', $p[0]).'.txt';
      file_put_contents($fl, $p[1]);
   }
?>

Sry but how to use this lol
 
scrapebox may be able to do this
@loopline may know the answer
thanks, however this is not something scrapebox can do. I mean your talking about exporting off your website.

You could however possibly build an article scraper module for this and let scrapebox crawl the entire website and scrape all the articles. so it should work fine.
 
I want to export the articles on my website to .txt but I can't find a plugin for this. Every export plugin allow you to export in csv and other formats but not txt.

Any idea what should I do?
It's a simple process, install an Aspose DOC Exporter. create a free account with aspose cloud and get an app id and key.once you sign up you can begin with export.
 
Back
Top