cURL 从 bash 的网页中提取了错误的超链接
cURL extracts the wrong hyperlink from a webpage in bash
我正在尝试使用 cURL 从 Adobe 中提取 hyperlink:
- 网站是https://get.adobe.com/air/
- link 是
https://get.adobe.com/air/download/?installer=Adobe_AIR_22.0_for_Win32&standalone=1
当使用 cURL 命令行时,我得到的 link 是默认的“http://www.adobe.com”,而不是上面的那个。
我怀疑 cURL 不是 "calling" 或 JavaScript 或 JQuery,它用正确的 hyperlink.
填充按钮
谁能给我指出正确的方向?
如何让 cURL 为该按钮生成或提取正确的 link?
cURL
只是执行一个 HTTP/S 请求。 HTTP 协议仅适用于文本,当返回 HTML 时,该文本可以包含浏览器和其他工具可以解释的标记,特别是 <img>
、<link>
和 <script>
.
所以你得到的文本就是这样;实际上以与浏览器相同的方式执行 javascript 涉及大量(轻描淡写)工作。
Selenium 等工具为现代网页的 "execute" HTML 提供编程机制。可能想去那里看看。
您可以使用 phantomjs.
创建这样的脚本
#! /usr/bin/phantomjs --ssl-protocol=any
var page = require('webpage').create(),
system = require('system'),
t, address;
if (system.args.length === 1) {
console.log('Usage: load.js <some URL>');
phantom.exit();
}
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
address = system.args[1];
page.open(address, function(status) {
if (status !== 'success') {
console.log('FAIL to load the address: ' + status);
} else {
var btn = page.content.match(/<a id="buttonDownload" .*download-button">/)
console.log(btn);
}
phantom.exit();
});
并调用它(如果你的 OS 支持 shebang)
$ ./load.js https://get.adobe.com/air
获得
<a id="buttonDownload" href="/air/download/?installer=Adobe_AIR_22.0_for_Win32&standalone=1" class="Button ButtonYellow download-button">
否则,将其用作
phantomjs --ssl-protocol=any load.js https://get.adobe.com/air
我正在尝试使用 cURL 从 Adobe 中提取 hyperlink:
- 网站是https://get.adobe.com/air/
- link 是
https://get.adobe.com/air/download/?installer=Adobe_AIR_22.0_for_Win32&standalone=1
当使用 cURL 命令行时,我得到的 link 是默认的“http://www.adobe.com”,而不是上面的那个。 我怀疑 cURL 不是 "calling" 或 JavaScript 或 JQuery,它用正确的 hyperlink.
填充按钮谁能给我指出正确的方向? 如何让 cURL 为该按钮生成或提取正确的 link?
cURL
只是执行一个 HTTP/S 请求。 HTTP 协议仅适用于文本,当返回 HTML 时,该文本可以包含浏览器和其他工具可以解释的标记,特别是 <img>
、<link>
和 <script>
.
所以你得到的文本就是这样;实际上以与浏览器相同的方式执行 javascript 涉及大量(轻描淡写)工作。
Selenium 等工具为现代网页的 "execute" HTML 提供编程机制。可能想去那里看看。
您可以使用 phantomjs.
创建这样的脚本
#! /usr/bin/phantomjs --ssl-protocol=any
var page = require('webpage').create(),
system = require('system'),
t, address;
if (system.args.length === 1) {
console.log('Usage: load.js <some URL>');
phantom.exit();
}
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
address = system.args[1];
page.open(address, function(status) {
if (status !== 'success') {
console.log('FAIL to load the address: ' + status);
} else {
var btn = page.content.match(/<a id="buttonDownload" .*download-button">/)
console.log(btn);
}
phantom.exit();
});
并调用它(如果你的 OS 支持 shebang)
$ ./load.js https://get.adobe.com/air
获得
<a id="buttonDownload" href="/air/download/?installer=Adobe_AIR_22.0_for_Win32&standalone=1" class="Button ButtonYellow download-button">
否则,将其用作
phantomjs --ssl-protocol=any load.js https://get.adobe.com/air