[英]how to retrieve json files from url inside a text file
I have to check the json data from an url using curl curl -H "User-agent: 'your bot 0.1'" url.json | jq
我必须检查来自 url 的 json 数据,使用 curl
curl -H "User-agent: 'your bot 0.1'" url.json | jq
curl -H "User-agent: 'your bot 0.1'" url.json | jq
this code is working curl -H "User-agent: 'your bot 0.1'" url.json | jq
此代码有效
i wanted try this for a.txt file containing 200 url like these我想试试这个包含 200 url 的 a.txt 文件
https://www.reddit.com/user/wanderer_007_.json https://www.reddit.com/user/wanderer_007_.json
https://www.reddit.com/... . https://www.reddit.com/...。
https://www.reddit.com/... . https://www.reddit.com/...。
https://www.reddit.com/... . https://www.reddit.com/...。
https://www.reddit.com/... . https://www.reddit.com/...。
these are just examples.这些只是例子。 but whenever I give the text file as an input
但每当我将文本文件作为输入
#!/usr/bin/bash
while read -r line; do
name="$line"
curl -H "User-agent: 'your bot 0.1'" $name | jq
done < test001.txt
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
but if I try to use the url individually it is working as intended但是如果我尝试单独使用 url 它会按预期工作
Try to wrap the filename in curl command with double quotes:尝试用双引号将 curl 命令中的文件名括起来:
curl -H "User-agent: 'your bot 0.1'" "$name" | jq
The error may be due to Bash interpreting some wierd characters in URLs specially.该错误可能是由于 Bash 专门解释了 URL 中的一些奇怪字符。 For example space in the URL may cause $name to split into 2 command-line arguments making curl unable to parse its inputs.
例如,URL 中的空格可能导致 $name 拆分为 2 个命令行 arguments,使 curl 无法解析其输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.