There are two ways to get Baidu data, one is to use the URL to get from the stream, the other is to open the browser directly. Text recognition (OCR) and then transcoding can be fast Baidu
Public Static voidMain (string[] args)throwsIOException {//URL link AddressString localpath = "http://www.baidu.com/s?tn=ichuner&lm=-1&word=" +Urlencoder.encode ("Jiangsu provincial capital", "gb2312") + "&rn=1"; URL URL=NewURL (LocalPath); //get the returned data directly based on the URLBufferedReader breaded =NewBufferedReader (NewInputStreamReader (Url.openstream (), "UTF-8")); while(Breaded.readline ()! =NULL) {//Print this dataSystem.out.println (Breaded.readline ()); } //Get system TypeString osname = System.getproperty ("Os.name", "" "); System.out.println (Osname); if(Osname.startswith ("Windows")) {//if the Windows system runtime.getruntime (). exec("rundll32 Url.dll,fileprotocolhandler" + localpath);//Open Browser } }
Runtime.getruntime (). EXEC () is the command that calls the computer
Java opens browser for Windows system