标签: curl

完成加载后卷曲抓取页面

我有一个需要一些时间才能完全加载的网址。但是当我使用curl将链接下载为html时,它会在完全加载页面之前实时下载html,我的意思是完全执行JavaScript。请帮助我如何停止卷曲直到页面完全加载或在 1 分钟后开始下载页面。

linux command-line curl

2
推荐指数
1
解决办法
1万
查看次数

将多个输入通过管道传输到 Ghostscript

我正在尝试使用 Ghostscript 创建一个单行 Linux 命令来合并两个 PDF 文件(从 URL 下载)。但是,我不想创建任何临时文件(一切都应该在内存中完成)。

以下命令似乎不起作用(我尝试通过进程替换来实现此目的)。

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=combined.pdf <(curl http://example.com/one.pdf) <(curl http://example.com/two.pdf)
Run Code Online (Sandbox Code Playgroud)

当我运行此命令时,它给出以下错误。

**** Warning:  An error occurred while reading an XREF table.
**** The file has been damaged.  This may have been caused
**** by a problem while converting or transfering the file.
**** Ghostscript will attempt to recover the data.
Error: /ioerror in --run--
Current allocation mode is local
Last OS error: Illegal seek
GPL Ghostscript 9.18: Unrecoverable error, …
Run Code Online (Sandbox Code Playgroud)

pipe curl ghostscript process-substitution

2
推荐指数
1
解决办法
1299
查看次数

`curl --cert` 和 `curl --cacert` 读取和写入哪些 HTTP 请求和响应标头?

来自https://curl.haxx.se/docs/httpscripting.html

在 HTTPS 世界中,您可以使用证书来验证您是否是您所声称的身份,作为普通密码的补充。Curl 支持客户端证书。所有证书都使用密码短语进行锁定,您需要先输入该密码,然后curl 才能使用该证书。密码短语可以在命令行上指定,如果没有指定,则在curl 查询时以交互方式输入。在 HTTPS 服务器上使用带有 curl 的证书,例如:

curl --cert mycert.pem https://secure.example.com
Run Code Online (Sandbox Code Playgroud)

curl 还尝试通过根据本地存储的 CA 证书包验证服务器的证书来验证服务器是否是其声称的服务器。验证失败将导致curl拒绝连接。然后,如果您想告诉curl 忽略无法验证服务器,则必须使用--insecure (-k)。有关服务器证书验证和 ca 证书捆绑包的更多信息,请参阅 SSLCERTS 文档,可在线获取: https: //curl.haxx.se/docs/sslcerts.html

有时您可能最终会得到自己的 CA 证书存储,然后您可以告诉curl 使用它来验证服务器的证书:

 curl --cacert ca-bundle.pem https://example.com/
Run Code Online (Sandbox Code Playgroud)

HTTP 请求和响应标头的作用curl --certcurl --cacert读写是什么?

谢谢。

http curl

2
推荐指数
1
解决办法
2万
查看次数

Linux Shell - 使用 sed 读取 json 时如何删除 JQ 生成的转义字符?

我正在尝试读取一个 json 文件并使用其输出来jq构建另一个 json,结合上述 json 文件和其他值,并将其传递给CURL

我用以下方式读取文件policies=$( sed 's/\\//g' policies.json)

我使用以下jq命令构建新的 json

BODY=$( jq -n \
            --arg cid "$chaincodeId" \
            --arg cv "$chaincodeV" \
            --arg ct "$chaincodeT" \
            --arg ar "$chaincodeArgs" \
            --arg pol "$policies" \
            '{chaincode_id: $cid, chaincode_version: $cv, chaincode_type: $ct, endorsement_policy: $pol}' )
Run Code Online (Sandbox Code Playgroud)

它对于前 4 个属性效果很好。但是,endorsement_policy 属性包含反斜杠,因此服务器无法读取通过curl 发送的属性。

body 的输出如下

{ "chaincode_id": "IdentityManager", "chaincode_version": "testcc2", "chaincode_type": "node", "endorsement_policy": "{\n \"identities\": [\n {\n \"role\": {\n \"name\": \"member\",\n \"mspId\": \"org1\"\n }\n },\n {\n \"role\": …
Run Code Online (Sandbox Code Playgroud)

shell scripting sed curl jq

2
推荐指数
1
解决办法
1万
查看次数

使用 dns 选项运行 CURL 时出现问题

我现在使用 curl 一段时间来调试我的非生产网络服务。

当我使用该--dns-servers选项时,我总是收到一条错误消息,指出找不到此功能:

curl --dns-servers _MY_DNS_SERVER_IP_ https://_MY_DOMAINS_
curl: (4) A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision.
Run Code Online (Sandbox Code Playgroud)

我的 curl 版本是 7.47.0,在 Ubuntu 16.04 桌面上运行。

从 curl 手册页(关于--dns-servers选项):

This option requires that libcurl was built with a resolver backend that supports this operation.
The c-ares backend is the only such one.  (Added in 7.33.0)
Run Code Online (Sandbox Code Playgroud)

是否需要安装另一个 curl 包,或者我错过了一些可选的依赖项?

任何提示似乎是什么问题?

networking ubuntu dns webserver curl

2
推荐指数
1
解决办法
1320
查看次数

`curl` 如何在 macOS 中访问 SSL 证书?

我使用的是 macOS 10.15.5 的 Macbook。我有 MacPorts,但我使用的是curl.

% curl --version
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
Run Code Online (Sandbox Code Playgroud)

当我尝试 d/l 最新的时youtube-dl,我收到证书错误:

% sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time …
Run Code Online (Sandbox Code Playgroud)

curl https macos

2
推荐指数
1
解决办法
9994
查看次数

在 shell 脚本中 curl --data-binary $'

我已经尝试了所有从 shell 脚本中进行 curl 的方法。这个卷发有一个

--data-binary $'
Run Code Online (Sandbox Code Playgroud)

我无法让我的脚本重新创建的部分。出于某种奇怪的原因,它会将 $ 移动到单引号内。任何想法如何解决它?

--data-binary '$
Run Code Online (Sandbox Code Playgroud)
curl -s  -H 'Connection: keep-alive' \
  -H 'Cache-Control: max-age=0' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'Origin: https://url.com' \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary6AiBMw0TyIybreRa' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: navigate' \
  -H 'Sec-Fetch-User: ?1' \
  -H 'Sec-Fetch-Dest: document' \
  -H 'Referer: https://url.com' \
  -H 'Accept-Language: en-US,en;q=0.9,es;q=0.8' \
  -H "Cookie: JSESSIONID=$jsession; __utmc=35664418; …
Run Code Online (Sandbox Code Playgroud)

curl

2
推荐指数
1
解决办法
840
查看次数

curl 在请求之间缺少暂停,wget 缺少动态文件输出名称,是否有现成的文件下载顺序范围的替代方案?

curl和两者都wget提供下载一系列文件([1-100]in curl{1..100}in wget)的能力,但它们每个都有一个缺点:curl在序列中的每次下载之间没有简单的方法来暂停。一些服务器在多次快速下载后会切断下载,无论如何,在下载之间暂停是礼貌和适当的,以成为一名优秀的爬虫公民。如果有人想在每个请求之间暂停 5 秒,我的理解是,如果没有额外的脚本,就没有办法做到这一点,而这些脚本基本上破坏了通过发出单个请求来对顺序范围提供内置支持的意义。

对此的解决方案是使用wget具有方便--wait=5标志的which来实现上述所需的结果。不幸的是,wget还有其他问题。它似乎与 URL 中的特殊字符斗争,并且无法使用 URL 周围的引号,因为该范围{1..100}似乎无法识别。这意味着有时需要手动转义特殊字符。这是可以管理的,但很烦人。

然而,更重要的是,wget不支持动态命名输出(-O这里的标志没有帮助)。尽管curl提供了方便,-o "#1.jpg"但似乎无法实现相同的动态结果,wget除非再次绕过内置的顺序范围支持并制作单个请求的脚本集合,或者rename在下载后必须或以其他方式编辑文件名。

这让我觉得这是一项相当常见的任务:下载一系列连续的源文件,在每个请求之间礼貌地暂停,并动态重命名输出。我是否缺少一些替代方案curlwget克服了上述两个问题:1)在每个请求之间暂停 2)动态输出文件名。

shell wget curl

2
推荐指数
1
解决办法
640
查看次数

如何使用jq从github api中提取信息字段

我正在尝试使用其 API 提取有关 github 存储库的一些信息,显然jq是要走的路。我可以使用此命令查看所有可用信息:

curl 'https://api.github.com/repos/tmux-plugins/tpm' | jq
Run Code Online (Sandbox Code Playgroud)

输出:

{
  "id": 19935788,
  "node_id": "MDEwOlJlcG9zaXRvcnkxOTkzNTc4OA==",
  "name": "tpm",
  "full_name": "tmux-plugins/tpm",
  "private": false,
  "owner": {
    "login": "tmux-plugins",
    "id": 8289877,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjgyODk4Nzc=",
    "avatar_url": "https://avatars.githubusercontent.com/u/8289877?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/tmux-plugins",
    "html_url": "https://github.com/tmux-plugins",
    "followers_url": "https://api.github.com/users/tmux-plugins/followers",
    "following_url": "https://api.github.com/users/tmux-plugins/following{/other_user}",
    "gists_url": "https://api.github.com/users/tmux-plugins/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/tmux-plugins/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/tmux-plugins/subscriptions",
    "organizations_url": "https://api.github.com/users/tmux-plugins/orgs",
    "repos_url": "https://api.github.com/users/tmux-plugins/repos",
    "events_url": "https://api.github.com/users/tmux-plugins/events{/privacy}",
    "received_events_url": "https://api.github.com/users/tmux-plugins/received_events",
    "type": "Organization",
    "site_admin": false
  },
  "html_url": "https://github.com/tmux-plugins/tpm",
  "description": "Tmux Plugin Manager",
  "fork": false,
  "url": "https://api.github.com/repos/tmux-plugins/tpm",
  "forks_url": "https://api.github.com/repos/tmux-plugins/tpm/forks",
  "keys_url": "https://api.github.com/repos/tmux-plugins/tpm/keys{/key_id}",
  "collaborators_url": "https://api.github.com/repos/tmux-plugins/tpm/collaborators{/collaborator}",
  "teams_url": "https://api.github.com/repos/tmux-plugins/tpm/teams", …
Run Code Online (Sandbox Code Playgroud)

shell api curl json jq

2
推荐指数
1
解决办法
304
查看次数

为什么我使用 curl 获得二进制输出

不确定是否可以共享我试图获取其来源的网站,但我认为有必要进行更好的解释。如果不是提前,我深表歉意

命令: curl -k -L -s https://www.mi.com

由于出现以下错误,由于某种原因,输出是二进制数据

Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
Run Code Online (Sandbox Code Playgroud)

如何阅读页面 HTML 源代码?谢谢!

binary curl

2
推荐指数
2
解决办法
6728
查看次数