我set -e在脚本的顶部。如何避免某些命令和进程退出代码的脚本终止?我在遵循代码示例时遇到困难:
我需要输出到变量和退出代码,但这并不set -e容易。
set -e
...
formoutput=$(yad --form --field="Subdomain" --field="Domain" --field="Web master username" \
--field="Apache group" --field='Webroot' \
--field='Webroot variables - ${homedir}(of webmaster) ${subdomain} ${webmaster} ${domain}:LBL' \
--field="Virtualhost ip or domain" \
--field="Virtualhost port" --field="Server admin email" \
--field="Create mysql user&db:CHK" \
--button="Cancel:3" --button="Save defaults:2" --button="Create:0" \
--title="Create apache virtualhost" \
--text='Subdomain are case sencetive for Webroot folder ${subdomain} variable' \
--focus-field=1 --center --window-icon="preferences-system" --width=600 \
"${config[subdomain]}" "${config[domain]}" "${config[webmaster]}" "${config[webgroup]}" \
"${config[webroot]}" "test" "${config[virtualhost]}" "${config[virtualport]}" …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取 Instagram 帖子的 json。获取数据的网址:
$url = "https://www.instagram.com/p/" . $_GET['media'] . "/?__a=1";
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中得到这个url 时 - 一切正常,json 返回。顺便说一句,浏览器未登录到 Instagram。但是当我使用 curl 或file_get_contents($url);它返回 http 代码 302 时,标题为“位置”到登录页面。
代码示例:
$url = "https://www.instagram.com/p/" . $_GET['media'] . "/?__a=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json') );
$data = curl_exec($ch);
curl_close($ch);
var_dump($data);
Run Code Online (Sandbox Code Playgroud)
也许应该修改 curl 选项以使其看起来像浏览器。
我尝试了与浏览器中相同的标题,包括 cookie,但没有运气,这似乎是不可能的。我已经使用这个 hack 编写了页面,最近停止工作了。使用 API 意味着重写所有内容,因为响应的数据是不同的。