LoginSignup
0
0

Pocketからエクスポートしたhtmlファイルをタブ区切りテキストにする

Last updated at Posted at 2024-04-14

「後で読む」サービスのPocket (Formerly Read It Later)は、エクスポート機能を利用することで、Pocketに登録された内容(URL, 追加日, タグ, タイトル)をHTMLとしてエクスポートすることができます。

ただ、何らかのアプリケーションやスクリプトで活用する場合、HTMLのままでは扱いにくいため、タブ区切りテキストやJSONなどの構造化データとして変換すると扱いやすくなります。

タブ区切りテキストであれば、以下のように正規表現と簡単なコマンドで出力することができます。

#!/bin/sh
echo -e "url\ttime_added\ttags\ttitle" > ril_export.txt
cat ril_export.html \
| sed -z 's/\t//g' \ 
| sed -z 's/\n/ /g' \
| sed -z 's/<li>/\n<li>/g' \
| sed -z 's/<\/li>/<\/li>\n/g' \
| grep '<li>' \
| sed 's/.*<li><a href="\(.*\)" time_added="\(.*\)" tags="\(.*\)">\(.*\)<\/a><\/li>/\1\t\2\t\3\t\4/g' >> ril_export.txt

元ファイルの例

liタグを含む行のみ抜粋

<li><a href="https://www.rasukarusan.com/entry/2024/04/08/110442" time_added="1713062104" tags="">LibreChat で Command R+ を使えるようにする</a></li>
<li><a href="https://azukiazusa.dev/blog/css-anchor-positioning/" time_added="1713061984" tags="">ポップアップが画面内に収まらない場合に自動的に表示位置を調整する CSS Anchor Positioning</a></li>
<li><a href="https://qiita.com/mksamba/items/2fdba4154dc85be7a7f9" time_added="1713060532" tags="">DirectConnectに直結していないVPCからオンプレサーバへアクセスする</a></li>
<li><a href="https://github.com/sourcegraph/awesome-code-ai" time_added="1713059376" tags="">sourcegraph/awesome-code-ai</a></li>
<li><a href="https://qiita.com/NagaJun/items/f7039929adf0bdf4ac7b" time_added="1713010618" tags="">JavaScript(html)でフロー図を作成(Draw2d) #JavaScript - Qiita</a></li>
<li><a href="https://github.com/drawdb-io/drawdb" time_added="1713000049" tags="">drawdb-io/drawdb</a></li>
<li><a href="https://qiita.com/Kanahiro/items/85573c9ae724df435a6a" time_added="1712990580" tags="">AWS Lambda Function URLs(関数URL)がCloudfrontのOAIに対応したので試す</a></li>
<li><a href="https://note.com/nepia_infinity/n/n447adec1c094" time_added="1712927680" tags="inoreader,monitoring feeds">【GAS】Google Apps Script活用事例 Slack APIを駆使してFindyの情報をスプレッドシートに吐き出せるようにす るスクリプト</a></li>
<li><a href="https://dev.classmethod.jp/articles/stay-in-the-loop-integrating-github-with-slack-for-real-time-project-updates/" time_added="1712927642" tags="">Stay in the Loop: Integrating GitHub with Slack for Real-Time Project Updat</a></li>

出力結果の例

url     time_added      tags    title
https://www.rasukarusan.com/entry/2024/04/08/110442     1713062104              LibreChat で Command R+ を使えるようにする
https://azukiazusa.dev/blog/css-anchor-positioning/     1713061984              ポップアップが画面内に収まらない場合に自動的に表示位置を調整する CSS Anchor Positioning
https://qiita.com/mksamba/items/2fdba4154dc85be7a7f9    1713060532              DirectConnectに直結していないVPCからオンプレサーバへアクセスする
https://github.com/sourcegraph/awesome-code-ai  1713059376              sourcegraph/awesome-code-ai
https://qiita.com/NagaJun/items/f7039929adf0bdf4ac7b    1713010618              JavaScript(html)でフロー図を作成(Draw2d) #JavaScript - Qiita
https://github.com/drawdb-io/drawdb     1713000049              drawdb-io/drawdb
https://qiita.com/Kanahiro/items/85573c9ae724df435a6a   1712990580              AWS Lambda Function URLs(関数URL)がCloudfrontのOAIに対応したので試す
https://note.com/nepia_infinity/n/n447adec1c094 1712927680      inoreader,monitoring feeds      【GAS】Google Apps Script活用事例 Slack APIを駆使してFindyの情報をスプレッドシートに吐き出せるようにするスクリプト
https://dev.classmethod.jp/articles/stay-in-the-loop-integrating-github-with-slack-for-real-time-project-updates/       1712927642              Stay in the Loop: Integrating GitHub with Slack for Real-Time Project Updat

出力結果よりURLのみ抜き出したい場合

cutコマンドを用いることで、URLなど特定の列のみ抜き出し可能

$ cut -f 1 ril_export.txt

出力結果の例

url
https://www.rasukarusan.com/entry/2024/04/08/110442
https://azukiazusa.dev/blog/css-anchor-positioning/
https://qiita.com/mksamba/items/2fdba4154dc85be7a7f9
https://github.com/sourcegraph/awesome-code-ai
https://qiita.com/NagaJun/items/f7039929adf0bdf4ac7b
https://github.com/drawdb-io/drawdb
https://qiita.com/Kanahiro/items/85573c9ae724df435a6a
https://note.com/nepia_infinity/n/n447adec1c094
https://dev.classmethod.jp/articles/stay-in-the-loop-integrating-github-with-slack-for-real-time-project-updates/
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0