加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 使用curl循环遍历url的Shell脚本

发布时间:2020-12-15 18:53:38 所属栏目:安全 来源:网络整理
导读:我一直在尝试创建一个简单的脚本,它将从.txt文件中获取一个查询列表,附加主url变量,然后擦除内容并将其输出到文本文件. 这是我到目前为止 #!/bin/bashurl="example.com/?q="for i in $(cat query.txt); do content=$(curl -o $url $i) echo $url $i echo $co
我一直在尝试创建一个简单的脚本,它将从.txt文件中获取一个查询列表,附加主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.
使用更多的报价!

> http://mywiki.wooledge.org/Quotes
> http://mywiki.wooledge.org/Arguments
> http://wiki.bash-hackers.org/syntax/words

改为:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读