Linux Terminal Access page

CURL --- Command line browser

This stuff is now one of the built-in command-line tool on the Mac, and its charm is evident

1)
apart from anything else, start with start here!

curl http://www.yahoo.com

After the carriage return, www.yahoo.com of html to splinters displayed on the screen of the ~~~~~

2)
ah, in order to keep down the page to read, is not it so?
curl http://www.yahoo.com> page.html

Sure, but you do not have too much trouble!
With built-in option curl just fine, able to save the results of http, with this the Option: -o
curl -o page.html http://www.yahoo.com

In this way, you can see a download progress indicator page appears on the screen. And so progress to 100% naturally slightly OK

3)
What? ! Not visit? Sure your proxy is not set up.
When using curl, use this option to specify the http proxy server used to access its ports: -x
curl -o -x 123.45.67.89:1080 page.html http://www.yahoo.com


4)
when visiting some sites more annoying, he uses a cookie to record session information.
Like IE / NN such a browser, of course, you can easily handle cookie information, but we curl it? .....
We learn this option: -D <- this is the response inside the http cookie information saved to a special file to
curl -x 123.45.67.89:1080 -o page.html -D cookie0001 .txt http://www.yahoo.com

In this way, when the page is saved to page.html same time, cookie information is also saved to the inside cookie0001.txt


5)
Then, when the next visit, how to continue to use the cookie information left it last? You know, a lot of sites are monitored by your cookie information
to judge whether you are no regulations visit their website.
This time we use this option to append the last cookie information to the http request to go inside: -b
curl -x -D cookie0002.txt page1.html 123.45.67.89:1080 -o -b cookie0001.txt HTTP: // the WWW .yahoo.com

In this way, we can simulate almost all of the IE operation to access the page!


6)
slightly and so ~~~~~ I seem to have forgotten what ~~~~~
right! Browser information ~ ~ ~ ~

Some hate sites always want us to use certain browsers to access them, sometimes even excessive, but also the use of some specific version ~ ~ ~ ~
NND, where there is time for it to find these weird browser is it! ?

Fortunately curl provides us with a useful option, allows us free to specify your own access to the claims of its own browser information: -A
curl -A "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com

In this way, access to the server-side requirements will think you are a running IE6.0 on 2000 Windows, hey hey hey, in fact, maybe you are using a Mac too!

The "Mozilla / 4.73 [en] (X11; U; Linux 2.2; 15 i686" you can tell the other party that you are ran on a PC Linux, use the Netscape 4.73, Ha ha ha


7)
Another common limitation method server, is to check referer http access. For example, you first visit the home page and then access inside the designated download page, referer address this second visit is the first visit after the success of the page address. In this way, as long as the server address referer find a visit to the download page is not the home page address, we can conclude that it was a steal even a ~~~~~

I hate hate ~ ~ ~ I just want to steal even ~~~~~! !
Fortunately curl gives us a set referer of the Option: -e
curl -A "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txt http://www.yahoo.com

In this way, you can lie to other servers, you click on a link from mail.yahoo.com over, Ha ha ha


8)
read, read, discovered something important missing! ----- download files using the curl

Just talked about, the download page to a file, you can use -o, download files as well.
For example, curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
here to teach you a new option: -O
capital O, so used: curl -O http: //cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
way, you can follow the file name on the server, there is automatically a local!

Come to a better use.
If the outside screen1.JPG there screen2.JPG, screen3.JPG, ...., screen10.JPG need to download, do we have to write a script to perform these operations?
Quit!
In the curl inside, so write on it:
curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG

Ha ha ha, powerful, right? ! ~ ~ ~

9)
again, we continue to explain to download!
curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG

Download so produced is
~ ZZH / 001.JPG
~ ZZH / 002.jpg
...
~ ZZH / 201.JPG
~ Nick / 001.JPG
~ Nick / 002.jpg
...
~ Nick / 201.JPG

Easy enough, right? Ha ha ha

Huh? I get too excited.
Since the file name under zzh / nick are 001, 002, ..., 201, downloaded files the same name, behind the front cover of the document gave out ~~~

It does not matter, we have Genghen!
curl -o # 2_ # 1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG

- This is the download ..... self-defined file name?
- head, Oh!

# 1 is variable, it refers to the {zzh, nick} In this section, the first ZZH value, the second value Nick
# 2 represented by a variable, the variable portion of the second segment is --- [001-201 ], was added one by one from the value of 001 201
Thus, it download the custom file name, this becomes:
after ~ zzh / 001.JPG ---> Download:: the original 001-zzh.JPG
original: ~ after the nick / 001.JPG ---> Download: 001-nick.JPG

As a result, not afraid file the same name, huh, huh


9)
Continue to speak download
our usual on the windows platform, flashget such tools can help us block parallel downloads, can resume broken.
curl in these areas is not lost anyone, hehe

For example, we download screen1.JPG in, suddenly dropped, and we can begin resume
curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG

Of course, you do not get a half flashget downloaded file to fool me ~ ~ ~ ~ other half to download software files may not necessarily be oh ~ ~ ~

Block download, we will be able to use this option: -r
illustrated
example, we have a http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 to download (Zhao teacher's phone reading: D )
we can use this command:
curl -o -r 0-10240 "zhao.part1" HTTP: /cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 & \
curl -r 10241-20480 - O "zhao.part1" HTTP: /cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 & \
curl -r 20481-40960 -o "zhao.part1" HTTP: /cgi2.tky.3web.ne .jp / ~ ZZH / zhao1.mp3 & \
curl -r 40961- -o "zhao.part1" HTTP: /cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3

This block can download it.
But you yourself need to merge these fragmented files together
if you use UNIX or Mac, with a cat zhao.part *> zhao.mp3 can
If you are using Windows, use copy / b to solve it, huh

Mentioned above are downloading the http protocol, in fact, also be able to use ftp.
Usage Well,
curl -u name: passwd the FTP: // ip: Port / path / File
or familiar
curl ftp: // name: passwd @ ip: port / path / file

 

10)
finished downloading, the next natural speaking uploaded slightly
uploading option is -T

For example, we pass a file to ftp: curl -T localfile -u name: passwd ftp: // upload_site: port / path /

Of course, you can also upload files to the http server
such as curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
note that the agreement at this time, using the HTTP PUT method

Just said PUT, hey, let old clothes naturally think of several other methos not say it!
GET and POST can not forget Oh.

http submit a form, commonly used mode is POST and GET mode

What option do not GET mode, just need to write the variables in the url inside it
, such as:
curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345

The option POST mode is -d

For example, curl -d "user = nickwolfe & password = 12345" http://www.yahoo.com/login.cgi
is equivalent to issuing a landing ~~~~~ apply to this site

The pattern in the end with a GET or POST mode, depending on the program settings across the server.

One thing to note is that the file upload files in POST mode, such as
<form method = "POST" enctype = "multipar / form-data" action = "http://cgi2.tky.3web.ne.jp/ ZZH ~ / up_file.cgi ">
<= the INPUT of the type name = the Upload File>
Go"> <= the INPUT of the type the Submit Nick name = value = "
</ form>
such a HTTP form, we use curl to simulate, in respect of a this syntax:
curl -F -F Nick localfile the Upload = @ = Go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

Luoluosuosuo talk so much, in fact, there are many, many tips curl and usage
such as https, when using a local certificate, so you can
curl -E localcert.pem https: // remote_server

As another example, you can use the dictionary to curl ~~~~~ by dict protocol
curl dict: //dict.org/d: computer

Guess you like

Origin www.cnblogs.com/yikemogutou/p/11210707.html
Recommended