【问题标题】:curl read dynamic valuescurl 读取动态值
【发布时间】:2019-03-21 19:04:48
【问题描述】:

我正在测试 curl,并且对这种语言非常陌生。

让我解释一下我在做什么。

"http://somewebsite.com/click?param1=10&param2=523" 这是我在浏览器中点击并使用 Inspect Element 的 url,我得到了以下 curl bash 值 --

curl 'http://somewebsite.com/click?param1=10&param2=523' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9' -H 'Cookie: pdval=9bc5d1fa982ff4c1e1f3d224' --compressed

现在每次我在浏览器中点击该网址时,参数“pdval”的值都会发生变化。

是否有任何选项可以在 Linux 中使用 curl 读取 bash 脚本中的 -H 值。

任何帮助都会很棒。谢谢。

【问题讨论】:

标签: linux bash curl


【解决方案1】:

由于 pdval 在 cookie 中,您可以使用 -b-c 选项进行 cookie 相关任务。

-c, --cookie-jar

(HTTP) 指定 curl 之后将所有 cookie 写入哪个文件 一个完成的操作。 Curl 从其内存中写入所有 cookie 在操作结束时将 cookie 存储到给定文件。如果不 cookie 是已知的,不会写入任何数据。该文件将被写入 使用 Netscape cookie 文件格式。如果将文件名设置为 单破折号“-”,cookie 将被写入标准输出。

-b, --cookie

(HTTP) 在 Cookie 标头中将数据传递给 HTTP 服务器。它是 据说以前从服务器收到的数据 “Set-Cookie:”行。数据格式应为“NAME1=VALUE1; NAME2=VALUE2"。

如果参数中没有使用“=”符号,则将其视为 要从中读取先前存储的 cookie 的文件名。

因此,如果您设置了-c 选项,那么 curl 会自动将 cookie 存储在一个文件中。您必须使用-b 告诉 curl 从该文件中获取 cookie。

所以你的命令应该如下:

curl 'http://somewebsite.com/click?param1=10&param2=523' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9' -b /tmp/somewebsite.cookie -c /tmp/somewebsite.cookie --compressed

【讨论】:

  • 这行理论上是做什么的 "-b /tmp/somewebsite.cookie -c /tmp/somewebsite.cookie"
  • @NavinMishra -c 选项告诉 curl 在哪里存储 cookie。该文件将使用 Netscape cookie 文件格式写入。您可以在编辑器中打开该文件,您将找到 cookie 键值。 -b 告诉 curl 从哪里读取 cookie。
猜你喜欢
  • 1970-01-01
  • 2016-03-10
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 2011-07-02
  • 2020-12-25
  • 2014-08-22
  • 1970-01-01
相关资源
最近更新 更多