真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

獲取網(wǎng)頁(yè)源代碼java 獲取網(wǎng)頁(yè)源代碼的函數(shù)

Java訪問(wèn)指定URL并獲取網(wǎng)頁(yè)源代碼

1.編寫useSourceViewer 類的基本框架,該類僅包括無(wú)返回值的main ()方法,該方法從參數(shù)中獲取URL,通過(guò)輸入緩沖和輸出緩沖將該URL 原碼輸出。

成都創(chuàng)新互聯(lián)長(zhǎng)期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為紅橋企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè),紅橋網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。

2.編寫useSourceViewer 類,代碼如下:

import java.net.*;

import java.io.*;

public class useSourceViewer

{

public static void main (String[] args)

{

if (args.length 0)

{

try

{

//讀入U(xiǎn)RL

URL u = new URL(args[0]);

InputStream in = u.openStream( );

// 為增加性能存儲(chǔ)輸入流

in = new BufferedInputStream(in);

// 將輸入流連接到閱讀器

Reader r = new InputStreamReader(in);

int c;

while ((c = r.read( )) != -1)

{

System.out.print((char) c);

}

Object o = u.getContent( );

System.out.println("I got a " + o.getClass().getName( ));

}

catch (MalformedURLException e)

{

System.err.println(args[0] + " is not a parseable URL");

}

catch (IOException e)

{

System.err.println(e);

}

} // end if

} // end main

} // end SourceViewer}

java程序讀取一個(gè)url頁(yè)面的源代碼

傳入一個(gè)url,返回源代碼; public static String getHTML(String url){// 獲取指定URL的網(wǎng)頁(yè),返回網(wǎng)頁(yè)內(nèi)容的字符串,然后將此字符串存到文件即可 try { URL newUrl = new URL(url); URLConnection connect = newUrl.openConnection(); connect.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); DataInputStream dis = new DataInputStream(connect.getInputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(dis,"UTF-8")); String html = ""; String readLine = null; while((readLine = in.readLine()) != null) { html = html + readLine; } in.close(); return html; }catch (MalformedURLException me){ System.out.println("MalformedURLException" + me); }catch (IOException ioe){ System.out.println("ioeException" + ioe); } return null; }

java中如何根據(jù)一個(gè)網(wǎng)址獲得該網(wǎng)頁(yè)的源代碼?

package test;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

public class HttpTest {

private String u;

private String encoding;

public static void main(String[] args) throws Exception {

HttpTest client = new HttpTest("", "UTF-8");

client.run();

}

public HttpTest(String u, String encoding) {

this.u = u;

this.encoding = encoding;

}

public void run() throws Exception {

URL url = new URL(u);// 根據(jù)鏈接(字符串格式),生成一個(gè)URL對(duì)象

HttpURLConnection urlConnection = (HttpURLConnection) url

.openConnection();// 打開(kāi)URL

BufferedReader reader = new BufferedReader(new InputStreamReader(

urlConnection.getInputStream(), encoding));// 得到輸入流,即獲得了網(wǎng)頁(yè)的內(nèi)容

String line; // 讀取輸入流的數(shù)據(jù),并顯示

while ((line = reader.readLine()) != null) {

System.out.println(line);

}

}

}

根據(jù)具體問(wèn)題類型,進(jìn)行步驟拆解/原因原理分析/內(nèi)容拓展等。

具體步驟如下:/導(dǎo)致這種情況的原因主要是……


網(wǎng)站名稱:獲取網(wǎng)頁(yè)源代碼java 獲取網(wǎng)頁(yè)源代碼的函數(shù)
本文地址:http://weahome.cn/article/dosodpd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部