Java Crawl Web Source

Source: Internet
Author: User

ImportJava.io.*; Importjava.net.*;  Public classtest{ Public Static voidMain (String args[]) {//determine whether the parameter is two, the correct usage for the Firstsocket site page    if(args.length!=2) {System.out.println ("Usage:firstsocket host Page\r\nexample:firstsocket www.google.com"); System.exit (0); }//Example: http://www.circul.org/index.php String strserver=args[0];//get the first parameterwww.circul.org

//
/index.php
Try{String hostname=strserver; intPort = 80; InetAddress Addr=Inetaddress.getbyname (hostname); System.out.println ("MyVar" +addr+ "\ r \ n"); Socket Socket=NewSocket (addr, port);//Create a socket//Send commandBufferedWriter WR =NewBufferedWriter (NewOutputStreamWriter (Socket.getoutputstream (), "UTF8")); Wr.write ("GET" + strpage + "http/1.0\r\n"); System.out.println ("POST" + strpage + "http/1.0\r\n"); Wr.write ("HOST:" + strserver + "\ r \ n"); System.out.println ("HOST:" + strserver + "\ r \ n"); Wr.write ("\ r \ n");     Wr.flush (); //receive the returned resultBufferedReader rd =NewBufferedReader (NewInputStreamReader (Socket.getinputstream ()));     String Line;  while(line = Rd.readline ())! =NULL) {System.out.println (line);     } wr.close (); Rd.close (); } Catch(Exception e) {System.out.println (e.tostring ());}} }

Java Crawl Web Source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.