bash 如何从 Chrome 复制 cookie?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21919156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:40:44  来源:igfitidea点击:

How do I copy cookies from Chrome?

bashgoogle-chromecookiescurl

提问by Hymancogdill

I am using bash to to POST to a website that requires that I be logged in first. So I need to send the request with login cookie. So I tried logging in and keeping the cookies, but it doesn't work because the site uses javascript to hash the password in a really weird fashion, so instead I'm going to just take my login cookies for the site from Chrome. How do get the cookies from Chrome and format them for Curl?

我正在使用 bash 发布到需要我先登录的网站。所以我需要用登录cookie发送请求。所以我尝试登录并保留 cookie,但它不起作用,因为该站点使用 javascript 以一种非常奇怪的方式散列密码,因此我将只从 Chrome 获取我的站点登录 cookie。如何从 Chrome 获取 cookie 并将其格式化为 Curl?

I'm trying to do this:

我正在尝试这样做:

curl --request POST -d "a=X&b=Y" -b "what goes here?" "site.com/a.php"

回答by that other guy

  1. Hit F12 to open the developer console (Mac: Cmd+Opt+J)
  2. Look at the Network tab.
  3. Do whatever you need to on the web site to trigger the action you're interested in
  4. Right click the relevant request, and select "Copy as cURL"
  1. 按 F12 打开开发者控制台(Mac:Cmd+Opt+J)
  2. 查看网络选项卡。
  3. 在网站上做任何你需要做的事情来触发你感兴趣的动作
  4. 右键单击相关请求,然后选择“复制为 cURL”

This will give you the curl command for the action you triggered, fully populated with cookies and all. You can of course also copy the flags as a basis for new curl commands.

这将为您提供触发操作的 curl 命令,其中包含 cookie 和所有内容。您当然也可以复制标志作为新 curl 命令的基础。

回答by user2537361

In Chrome:

在 Chrome 中:

  • Open web developer tools (view -> developer -> developer tools)
  • Open the Application tab (on older versions, Resources)
  • Open the Cookies tree
  • Find the cookie you are interested in.
  • 打开 Web 开发人员工具(查看 -> 开发人员 -> 开发人员工具)
  • 打开应用程序选项卡(在旧版本上,资源)
  • 打开饼干树
  • 找到您感兴趣的 cookie。

In the terminal

在终端

  • add --cookie "cookiename=cookievalue"to your curl request.
  • 添加--cookie "cookiename=cookievalue"到您的卷曲请求中。

回答by andDevW

There's an even easier way to do this in Chrome/Chromium.
The open source Chrome extension cookietxt-exportexports cookie data in a cookies.txt file, and generates an optional ready-made wget command.

在 Chrome/Chromium 中有一种更简单的方法可以做到这一点。
开源 Chrome 扩展 cookietxt-export在 cookies.txt 文件中导出cookie 数据,并生成可选的现成 wget 命令。

*I have nothing to do with the extension, it just works really well.

*我与扩展无关,它真的很好用。

回答by Kyle Parisi

I was curious if others were reporting that chrome doesn't allow "copy as curl" feature to have cookies anymore.

我很好奇其他人是否报告说 chrome 不允许“复制为 curl”功能再有 cookie。

It then occurred to me that this is like a security idea. If you visit example.com, copying requests as curl to example.comwill have cookies. However, copying requests to other domains or subdomains will sanitize the cookies. a.example.comor test.comwill not have cookies for example.

然后我想到这就像一个安全理念。如果您访问example.com,将请求复制为 curlexample.com将有 cookie。但是,将请求复制到其他域或子域将清理 cookie。 a.example.com或者test.com不会有cookies。