当前位置: 首页 > 工具软件 > HtmlUnit > 使用案例 >

htmlunit解析页面

锺离浩慨
2023-12-01

 

htmlunit相当于java的一个浏览器,可以分析页面,获得页面数据

 

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
final WebClient wc = new WebClient();
		wc.setJavaScriptEnabled(false);
		WebRequestSettings settings = new WebRequestSettings(new URL(
				QUERY_FORM_URL + "&cph=" + vehicleNo + "&cx=" + vehicleColor));
		settings.setCharset("gb2312");
		HtmlPage page =  (HtmlPage) wc.getPage(settings);

		List<HtmlTable> tables = page.getDocumentHtmlElement()
				.getHtmlElementsByTagName("table");

 

先关连接:

http://htmlunit.sourceforge.net/

http://htmlparser.sourceforge.net/

 类似资料: