2013-04-21 26 views
17

私は、.txtファイルからクエリのリストを取得し、メインのurl変数を追加してコンテンツをスクラップしてテキストに出力する単純なスクリプトを作成しようとしていますファイル。curlを使用してURLをループするシェルスクリプト

は、ここで私がこれまで持っているものです。

#!/bin/bash 

url="example.com/?q=" 
for i in $(cat query.txt); do 
    content=$(curl -o $url $i) 
    echo $url $i 
    echo $content >> output.txt 
done 

リスト:

images 
news 
stuff 
other 

エラーログ:

curl: (6) Could not resolve host: other; nodename nor servname provided, or not known 
example.com/?q= other 

私はまっすぐに、コマンドラインからこのコマンドを使用する場合、私はいくつかを取得しますファイルに出力:

curl -L http://example.com/?q=other >> output.txt 

最終的に私は、出力がなりたい:

fetched: http://example.com/?q=other 
content: the output of the page 

followed by the next query in the list. 

答えて

3

あなたは、ネストされた引用符を持って、このような何かしてみてください:

関連する問題