導航:首頁 > 文件教程 > htmlunit本地文件

htmlunit本地文件

發布時間:2023-07-18 11:22:41

『壹』 如何用htmlunit把網頁上的flash截取下來

java">importjava.io.FileOutputStream;
importjava.io.InputStream;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;

importorg.apache.commons.io.IOUtils;

importcom.gargoylesoftware.htmlunit.Page;
importcom.gargoylesoftware.htmlunit.WebClient;

publicclassDownloadFile{
publicstaticvoidmain(String[]args)throwsException{
StringbaseUrl="http://hanyu.iciba.com/hanzi/1.shtml";
StringbihuaRegex="class="guanggao"[^<]*<[^<]*<param\s*name="movie"\s*value="([^"]*)";
StringaSoundRegex="class="js12">ā.*?name="FlashVars"\s*value="f=([^"]*)";
StringeSoundRegex="class="js12">ē.*?name="FlashVars"\s*value="f=([^"]*)";
WebClientclient=newWebClient();
client.getOptions().setCssEnabled(false);
client.getOptions().setJavaScriptEnabled(false);
client.getOptions().(false);
client.getOptions().(false);
Pagepage=client.getPage(baseUrl);
Stringsource=page.getWebResponse().getContentAsString();
MatchermBihuan=Regex(source,bihuaRegex);
MatchermA=Regex(source,aSoundRegex);
MatchermE=Regex(source,eSoundRegex);
while(mBihuan.find()){
Stringurl="http://hanyu.iciba.com/"+mBihuan.group(1);
page=client.getPage(url);
saveFile(page,"d:/testDownload/bihua.swf");
}
while(mA.find()){
Stringurl=mA.group(1);
page=client.getPage(url);
saveFile(page,"d:/testDownload/a.mp3");
}
while(mE.find()){
Stringurl=mE.group(1);
page=client.getPage(url);
saveFile(page,"d:/testDownload/e.mp3");
}
}

publicstaticMatcherRegex(Stringsource,Stringregex){
Patternp=Pattern.compile(regex,Pattern.DOTALL);
returnp.matcher(source);
}

publicstaticvoidsaveFile(Pagepage,Stringfile)throwsException{
InputStreamis=page.getWebResponse().getContentAsStream();
FileOutputStreamoutput=newFileOutputStream(file);
IOUtils.(is,output);
output.close();
}
}

註:附件只是下載下來的文件,並不是代碼。代碼就貼上來的這些。如只是想知道方法,並不需要下載附件。

『貳』 GB2312 的編碼,繁體內容變成亂碼,怎麼解決

第一步:下載htmlunit的源代碼,在com\gargoylesoftware\htmlunit\util目錄下有個EncodingSniffer文件,其中就有獲取頁面編碼的情況,大概在626行encoding = encoding.toUpperCase(Locale.ROOT);後邊添加if(encoding.equals("GB2312"))encoding="GBK";

第二步:大概在715行charset = charset.toUpperCase(Locale.ROOT);後邊添加if(charset.equals("GB2312"))charset="GBK";

原理:gb2312支持的字元集編碼比較小,GBK兼容並且大,可以直接轉GBK的,所以獲取頁面的時候,htmlunit本身會調用這個EncodingSniffer類,將其中遇到gb2312的情況,統一變成gbk。

比較麻煩就是要下載htmlunit源碼,做個編譯後,把生成的EncodingSniffer.class文件覆蓋到maven引用的包對應的class文件中。

『叄』 如何從網頁捉取JS動態數據

代碼比較簡單,直接看就可以了,需要注意的是,由於瀏覽器查詢需要時間,在查詢的過程中,應該讓主線程休眠一段時間,才能保證htmlunit瀏覽器已經查詢完畢。

import java.util.concurrent.TimeUnit;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableBody;

public class Entrance {

public static void main (String[] args ) throws Exception
{
String webUrl = "http://www.xy2046.com/xypk10.aspx?T=234&day=2016-05-29";
HtmlPage page = getHtmlPage(webUrl);
final HtmlTable div = (HtmlTable) page.getElementById("mytable");
HtmlTableBody tbody = (HtmlTableBody) div.getBodies().get(0);
printTable(tbody);
System.err.println("查詢數據成功");
}
答案可在CSDN中找到。

『肆』 java相關。爬蟲問題,關於新浪微博。謝謝!

1.Java中的所有類,必須被裝載到jvm中才能運行,這個裝載工作是由jvm中的類裝載器完專成的,類裝載器所做的工作實質是把類屬文件從硬碟讀取到內存中
2.java中的類大致分為三種:
1.系統
2.擴展類
3.由程序員自定義的類

3.類裝載方式,有兩種
1.隱式裝載, 程序在運行過程中當碰到通過new 等方式生成對象時,隱式調用類裝載器載入對應的類到jvm中。
2.顯式裝載, 通過class.forname()等方法,顯式載入需要的類

想必您肯定也上網查過,但是我想具體是什麼機制,屬於內部的機密了吧。畢竟網上查的到的話,那結果可想而知了。

閱讀全文

與htmlunit本地文件相關的資料

熱點內容
現在哪裡開設了編程課 瀏覽:230
漫一網路培訓學校有哪些 瀏覽:752
酷狗app如何在電腦同步播放 瀏覽:668
雲浮微信群 瀏覽:344
公司文件打不開 瀏覽:267
LOL的設置文件在哪裡 瀏覽:254
線上開庭是什麼app 瀏覽:526
新中大軟體怎麼設置文件夾 瀏覽:807
git刪除文件夾 瀏覽:353
皇室戰爭怎麼升級競技場 瀏覽:447
雅虎統計工具 瀏覽:741
edgepdf文件分類 瀏覽:901
cad為什麼捕捉不到外部參照文件 瀏覽:935
重慶一共有多少個網站 瀏覽:34
k8s配置文件env創建失敗 瀏覽:197
編程序在電腦上叫做什麼 瀏覽:92
qq閱讀可賺 瀏覽:21
怎樣查找web儲存文件圖片 瀏覽:681
人口檔案資料庫包括什麼信息 瀏覽:709
手機有什麼好玩的星戰網路游戲 瀏覽:15

友情鏈接