URLリストからURL +タイトルを自動的に生成する方法は? (bashまたはその他のツールを使用)

URLリストからURL +タイトルを自動的に生成する方法は? (bashまたはその他のツールを使用)

Linux Bashを使用している場合は、次のコマンドを使用してテキストファイルを変換するにはどうすればよいですか?

http://example.org/
https://en.wikipedia.org/wiki/Main_Page
https://www.youtube.com/watch?v=mGQFZxIuURE

入力する:

http://example.org/ Example Domain
https://en.wikipedia.org/wiki/Main_Page Wikipedia, the free encyclopedia
https://www.youtube.com/watch?v=mGQFZxIuURE Mike Perry - The Ocean (ft. Shy Martin) - YouTube

または、次のように入力してください。

http://example.org/
Example Domain

https://en.wikipedia.org/wiki/Main_Page 
Wikipedia, the free encyclopedia

https://www.youtube.com/watch?v=mGQFZxIuURE
Mike Perry - The Ocean (ft. Shy Martin) - YouTube

どうすればいいですか?

  1. ファイルのURLリストからURLを抽出し、
  2. ページを読み込み、
  3. ページタイトルを抽出し、
  4. 同じ行または直後の行のURLの後にページタイトルを追加し、

リスト内の各後続URLに対して手順1〜4を実行しますか?

Linux Bashを使用していない場合は何がありますか?

ベストアンサー1

curlヘヘ子犬:

while IFS= read -r url
do
   printf "%s " "$url"
   curl -sL "$url" | # fetch the page
       pup 'head title:first-of-type text{}' # get the text of the first title tag in head
done < input

おすすめ記事