专业的建网站公司地址,欢迎访问中国建设银行网上银行网站,郑州品牌网站建设官网,app是什么公司0 前言
curl是Linux中的一款综合性网络传输工具#xff0c;既可以上传也可以下载#xff0c;支持HTTP、HTTPS、FTP等30余种常见协议。
该命令选项超多#xff0c;在学习笔记68中#xff0c;我们列举了该命令的部分实例#xff0c;今天继续通过实例来研究curl命令的功能… 0 前言
curl是Linux中的一款综合性网络传输工具既可以上传也可以下载支持HTTP、HTTPS、FTP等30余种常见协议。
该命令选项超多在学习笔记68中我们列举了该命令的部分实例今天继续通过实例来研究curl命令的功能和用法。
1 curl命令应用实例
1.1 跟随重定向curl -L 统一资源定位符
在访问一个网页时如果这个网页已经移动到另一个站点时会发送一个HTTP Loaction header作为请求然后将请求重定向到新的地址上。
然而curl在默认情况下不会发送HTTP Location headers(重定向)这时我们可以指定 -L 选项来跟随重定向。
例如我们打开g.cn时会自动重定向跳转到 google.cn。
当我们使用命令 curl g.cn时看到的是g.cn的代码。
要想看到google.cn的代码可以在命令中指定-L选项即 curl -L g.cn
purpleEndurer bash ~] curl g.cn
HTMLHEADmeta http-equivcontent-type contenttext/html;charsetutf-8
TITLE301 Moved/TITLE/HEADBODY
H1301 Moved/H1
The document has moved
A HREFhttps://google.cn/here/A.
/BODY/HTML
[purpleEndurer bash ~] curl -L g.cn
!DOCTYPE html
html langzhheadmeta charsetutf-8titleGoogle/titlestylehtml { background: #fff; margin: 0 1em; }body { font: .8125em/1.5 arial, sans-serif; text-align: center; }h1 { font-size: 1.5em; font-weight: normal; margin: 1em 0 0; }p#footer { color: #767676; font-size: .77em; }p#footer a { background: url(//www.google.cn/intl/zh-CN_cn/images/cn_icp.gif) top right no-repeat; padding: 5px 20px 5px 0; }ul { margin: 2em; padding: 0; }li { display: inline; padding: 0 2em; }div { -moz-border-radius: 20px; -webkit-border-radius: 20px; border: 1px solid #ccc; border-radius: 20px; margin: 2em auto 1em; max-width: 650px; min-width: 544px; }div:hover, div:hover * { cursor: pointer; }div:hover { border-color: #999; }div p { margin: .5em 0 1.5em; }img { border: 0; }/style/headbodydiva hrefhttps://www.google.com.hk/webhp?hlzh-CNamp;sourceidcnhpimg src//www.google.cn/intl/zh-CN_cn/landing/cnexp/google-search.png altGoogle width586 height257/ah1a hrefhttps://www.google.com.hk/webhp?hlzh-CNamp;sourceidcnhpstrong idtargetgoogle.com.hk/strong/a/h1p请收藏我们的网址/divp idfooterspanICP证合字B2-20070004号/span/p/body
/html
[purpleEndurer bash ~] 1.2 断点续传curl -C - -O 统一资源定位符
在Windows中我们可以使用迅雷等的软件进行断点续传。
在Linux中curl可以通过-C选项同样可以达到相同的断点续传效果。
我们以下载 QQ Linux版 文件https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.12_240808_amd64_01.deb 为例。 [purpleEndurer bash ~] ls
Code
[purpleEndurer bash ~] curl -O https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.12_240808_amd64_01.deb% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed13 145M 13 19.0M 0 0 6154k 0 0:00:24 0:00:03 0:00:21 6153k^C
[purpleEndurer bash ~] ls
Code QQ_3.2.12_240808_amd64_01.deb
[purpleEndurer bash ~] du QQ_3.2.12_240808_amd64_01.deb
22528 QQ_3.2.12_240808_amd64_01.deb
[purpleEndurer bash ~] curl -C - -O https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.12_240808_amd64_01.deb
** Resuming transfer from byte position 23068672% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed
100 123M 100 123M 0 0 26.0M 0 0:00:04 0:00:04 --:--:-- 28.1M
[purpleEndurer bash ~] ls
Code QQ_3.2.12_240808_amd64_01.deb
[purpleEndurer bash ~] du QQ_3.2.12_240808_amd64_01.deb
148708 QQ_3.2.12_240808_amd64_01.deb
[purpleEndurer bash ~] 说明
1.使用ls命令查看当前目录内容只有一个Code目录。
2.使用 curl -C https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.12_240808_amd64_01.deb 命令开始下载文件文件大小是145MB。
3.在下载进度达到19%时按Ctrl c 终止下载
4. 使用ls命令查看当前目录内容除了之前已经存在的Code目录还多了一个文件QQ_3.2.12_240808_amd64_01.deb。
5.使用du命令查看文件QQ_3.2.12_240808_amd64_01.deb的大小只有22528KB19M。
6.使用命令curl -C - -O https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.12_240808_amd64_01.deb开始断点续传
7.使用使用ls命令查看当前目录内容仍然只有Code目录和文件QQ_3.2.12_240808_amd64_01.deb。
8.使用du命令查看文件QQ_3.2.12_240808_amd64_01.deb的大小有148708KB即145MB。
1.3 使用代理curl -x 代理服务器地址:端口 统一资源定位符
在很多时候上网需要用到代理服务器(比如是使用代理服务器上网或者因为使用curl别人网站而被别人屏蔽IP地址的时候)幸运的是curl提供了-x选项来支持我们设置代理
[purpleendurer bash ~ ] curl -x 127.0.0.1:1080 http://g.cn
curl: (7) Failed connect to 127.0.0.1:1080; Connection refused
[purpleendurer bash ~ ] curl -x 127.0.0.1:80 http://g.cn
curl: (7) Failed connect to 127.0.0.1:80; Connection refused
[purpleendurer bash ~ ] curl -x 47.92.194.235:4000 http://g.cn
htmlheadtitleEasy Restaurant Report System/title/headbody/body/html
[purpleendurer bash ~ ] curl -x 47.92.194.235:4000 http://blog.csdn.net/purpleendurer
htmlheadtitleMy Foods/title/headbody/body/html
[purpleendurer bash ~ ] curl -x 8.130.74.114:80 http://g.cn
htmlheadtitleD-LINK/title/headbody/body/html
[purpleendurer bash ~ ] curl -x 8.130.74.114:80 http://blog.csdn.net/purpleendurer
htmlheadtitlePbxHosting | Servicios de Telefonia IP/title/headbody/body/html
[purpleendurer bash ~ ] 1.4 指定浏览器类型和版本curl -A 浏览器User-Agent 统一资源定位符
有些网站需要使用特定的浏览器去访问有些还需要使用某些特定的版本。curl提供的-A选项可以让我们指定浏览器类型和版本去访问网站。
我们以访问csdn.net为例。
1.4.1 正常访问curl https://www.csdn.net | more
[purpleendurer bash ~ ] curl https://www.csdn.net | more% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0!doctype htmlhtml langzh data-server-renderedtrueheadtitleCSDN - 专业开发者社区/title meta namekeywords contentCSDN博客,CSDN学院,CSDN论坛,CSDN直播 meta namedescriptio
n contentCSDN是全球知名中文IT技术交流平台,创建于1999年,包含原创博客、精品问答、职业培训、技术论坛、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区. meta http-equivconten
t-type contenttext/html;charsetutf-8 meta nameviewport contentinitial-scale1, maximum-scale1, user-scalableno, minimal-ui meta namereferrer contentalways !---- !----!---- script srchttps://g.csdnimg.cn/tingyun/tingyun.js/script!---- !---- !---- link relshortcut icon hrefhttps://g.csdnimg.cn/static/logo/favicon32.ico typeimage/x-icon link relcanonical hrefhttps://www.csdn.net !---- meta nametoolbar content{type:0,fixModel:1,model:normal} /meta namereport content{spm:1000.2115} /script srchttps://g.csdnimg.cn/??lib/jquery/1.12.4/jquery.min.js,user-tooltip/2.7/user-tooltip.js,lib/qrcode/1.0.0/qrcode.min.js/script script src//g.csdnimg.cn/common/csdn-rep
ort/report.js typetext/javascript/script script srchttps://g.csdnimg.cn/user-ordercart/2.0.1/user-ordercart.js?ts2.0.1/script!---- script srchttps://g.csdnimg.cn/common/csdn-login-box/csdn-login-box.js defer/scriptscript srchttps://g.csdnimg.cn/user-ordertip/3.0.2/user-ordertip.js?t3.0.2/script!---- !---- !---- !---- scriptwindow.TINGYUN window.TINGYUN.init window.TINGYUN.init(function (ty_rum) {ty_rum.server { event_timeout: 60000, dr_threshold: 4000, opt_custom_param_rule: [], cross_page_delay: 3000, router_enable: true, fp_threshold: 2000, toke
n: 568934913a6343de840a781ca5eaba4b, beacon: wkbrs1.tingyun.com, trace_threshold: 7000, x_server_switch: true, ignore_err: false, id: hWg-u0rE5b8, key: Z1Tu5hoKb
Gw, fs_threshold: 4000 };});/script!---- script srchttps://g.csdnimg.cn/common/csdn-toolbar/csdn-toolbar.js?v1716884627340 defer/script!----link relstylesheet hrefhttps://csdnimg.cn/release/cmsfe/public/css/common.902bcda2.csslink relstylesheet hrefhttps://csdnimg.cn/release/cmsfe/public/css/tpl/www-inde
x-new/index.1d6c87f8.css/head bodydiv idtoolbarBox stylemin-height: 48px;/div div idappdivdiv classmaindiv classpage-container page-componentdivdiv classho
me_wrapdiv classcontent_wrapdiv idfloor-nav_557 floor-index0div comp-data[object Object] floor-data[object Object] classblog-nav-tag data-v-f8e9e086div classblog-na
v data-v-f8e9e086img srchttps://img-home.csdnimg.cn/images/20220107105619.png alt classblog-nav-down data-v-f8e9e086 div classblog-nav-box data-v-f8e9e086ul classdef data-v
-f8e9e086!---- !---- !---- !---- !---- !---- li classnavigation-right data-v-f8e9e086a hrefhttps://blog.csdn.net/nav/back-end data-report-click{quot;spmquot;:quot;10
01.2100.3001.7366quot;,quot;extend1quot;:quot;back-endquot;} data-report-view{quot;spmquot;:quot;1001.2100.3001.7366quot;,quot;extend1quot;:quot;back-endquot;} data-v-f8e9e086
后端/a/lili classnavigation-right data-v-f8e9e086a hrefhttps://blog.csdn.net/nav/web data-report-click{quot;spmquot;:quot;1001.2100.3001.7366quot;,quot;extend1quot;:quot;
webquot;} data-report-view{quot;spmquot;:quot;1001.2100.3001.7366quot;,quot;extend1quot;:quot;webquot;} data-v-f8e9e086前端/a/lili classnavigation-right data-v-f8e9e086
a hrefhttps://blog.csdn.net/nav/mobile data-report-click{quot;spmquot;:quot;1001.2100.3001.7366quot;,quot;extend1quot;:quot;mobilequot;} data-report-view{quot;spmquot;:quot;1
001.2100.3001.7366quot;,quot;extend1quot;:quot;mobilequot;} data-v-f8e9e086移动开发/a/lili classnavigation-right data-v-f8e9e086a hrefhttps://blog.csdn.net/nav/lang data-re
port-click{quot;spmquot;:quot;1001.2100.3001.7366quot;,quot;extend1quot;:quot;langquot;} data-report-view{quot;spmquot;:quot;1001.2100.3001.7366quot;,quot;extend1quot;:quot;
langquot;} data-v-f8e9e086编程语言/a/lili classnavigation-right data-v-f8e9e086a hrefhttps://blog.csdn.net/nav/java data-report-click{quot;spmquot;:quot;1001.2100.3001.736
--More-- 从反馈的网页代码来看网页是可以正常浏览的。
1.4.2 指定 使用微软IE 6.0 访问curl -A Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.2) https://www.csdn.net [purpleendurer bash ~ ] curl -A Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.2) https://www.csdn.net
htmlbodyscript languagejavascript window.onloadsetTimeout(cy(173), 200); function cy(YL) {var qo, mo, no, oo [0xaa,0x07,0x93,0xba,0xa8,0x89,0xb2,0x9a,0x23,0xf0,0x79,0xa8,0x64,0x0d,0xb5,0xdd,0x46,0x2e,0xf5,0xe4,0x94,0xdc,0xa2,0x70,0x8f,0xd4,0xf9,0xa4,0x0b,0xd2,0x36,0x5d,0x26,0x0e,0x75,0x7a,0x6b,0xd2,0x5b,0x82,0x6a,0x59,0x80,0xad,0x3b,0xa9,0xbe,0xac,0xeb,0x79,0xe8,0xf5,0xdd,0x6b,0x8e,0x7c,0xe3,0xcb,0xb9,0x21,0x8f,0x5d,0xe4,0x12,0xe7,0x56,0xa3,0xb8,0xe5,0x6d,0x94,0x85,0xa7,0x16,0x84,0x32,0xa7,0x98,0x32,0x08,0x0f,0x96,0x05,0xf5,0xff,0x07,0x34,0x61,0xd6,0xc7,0xdc,0x0a,0x31,0xa0,0x28,0x2f,0x22,0x77,0xc4,0xd1,0xb9,0x6f,0xa9,0x91,0x00,0xe9,0x5f,0x0d,0x8e,0x9b,0xd0,0x9e,0x6c,0x3a,0xe0,0x2e,0x1c,0x6a,0xa0,0xef,0x6a,0x52,0xa0,0xe5,0x4e,0x53,0x28,0x10,0x35,0x24,0x09,0xb1,0xc5,0x4e,0x1f,0x6e,0xdb,0xf0,0x6b,0x5c,0xc7,0xad,0x55,0x46,0x9b,0xb0,0x7e,0xcd,0x1b,0xb0,0xef,0xfd,0x0b,0xc0,0xce,0xfb,0xc1,0x18,0x67,0x0b,0xf7,0xb9,0x5c,0x8a,0xd9,0xa1,0x4a,0x33,0x15,0x7c,0xe4,0x6d,0x5c,0xec,0x73,0x9a,0xc7,0x8f,0x18,0xa8,0x79,0x02,0xe9,0xb7,0xe5,0x35,0x85,0xca,0x32,0xff,0x48,0x37,0xea,0x9b,0xc9,0x19,0x42,0x2a,0xda,0x02,0xef,0xf4,0xdc,0x8c,0x8d,0xbb,0x61,0xc9,0x52,0x1a,0x48,0xf0,0x96,0x27,0xee,0x97,0xfb,0x23,0x09,0xf1,0xd9,0x62,0x14,0xd9,0x6a,0x33,0xdb,0x03,0x53,0xba,0x88,0xf0,0x91,0x1a,0x3a,0x29,0xe0,0x89,0x9e,0x3b];qo qo238; do{oo[qo](-oo[qo])0xff; oo[qo](((oo[qo]3)|((oo[qo]5)0xff))-194)0xff;} while(--qo2);; eval(qo);qo 237; do { oo[qo] (oo[qo] - oo[qo - 1]) 0xff; } while (-- qo 3 );qo 1; for (;;) { if (qo 237) break; oo[qo] ((((((oo[qo] 40) 0xff) 248) 0xff) 6) 0xff) | (((((oo[qo] 40) 0xff) 248) 0xff) 2); qo;}po ; for (qo 1; qo oo.length - 1; qo) if (qo % 6) po String.fromCharCode(oo[qo] ^ YL);eval(qoeval;qo(po););} /script /body/html[purpleendurer bash ~ ] 2001年微软公司推出了IE浏览器最“经典”的6.0版本并在2003年走上巅峰IE浏览器各个版本占据全球市场95%的份额。那是IE浏览器的黄金时代。
时过境迁微软IE 6.0 是很古老的浏览器了csdn.net应该不再支持它了所以返回的代码跟1.4.1不同。