シングルカールコマンドでWebサイトのhttpダンプとヘッダーを取得するには?

シングルカールコマンドでWebサイトのhttpダンプとヘッダーを取得するには?

Webサイトをインポートして(複数のリダイレクトに-Lを使用できます)、HTMLコンテンツを次のファイルに保存する必要があります。[HTTP_Status_code]_[ウェブサイト名].html

現在、私は2つのカール呼び出しを使用しています。 1 つはダンプ用、もう 1 つはヘッダー用です。一つに合わせる方法はありますか?

スクリプト:

cat url_list.txt | while read line; do 
if curl  -L  $line -o `curl -I $line 2>/dev/null | head -n 1 | cut -d$' ' -f2`_`basename $line`.html 
 then
   :
 else
    echo $line >>error.txt
fi 
done

編集:最後にリダイレクトされたヘッダーを見つける必要があります。

ベストアンサー1

何について

cat url_list.txt | while read line; do 
if curl  -D  tmp_status.txt -L  $line -o tmp_file.html 
then
   mv tmp_file.html $(awk '/HTTP/  { print $2}' tmp_status.txt)_$(basename $line)
else
   echo $line >>error.txt
   # processing from tmp_status
fi 
done
  • カールコールは1つだけで、後処理も1つです。

おすすめ記事