抓取网页
public String getPageWeather(String weatherCode) {
String WEATHER_ROOT = sysConf.getValue("WEATHER_JSON");
String weatherUrl = WEATHER_ROOT + weatherCode + ".html";
logger.info("网页抓取开始,地址 【" + weatherUrl + " 】");
String sresult = "";
/*try {
HttpResult result = HttpUtil.getInstance().get(weatherUrl, "utf-8");
if (result.getOK()) {
logger.info("抓取成功");
sresult = result.getContent();
}
} catch (Exception e) {
e.printStackTrace();
return "";
}*/
sresult = this.getPageContent(weatherUrl, "", 50000000);
System.out.println(sresult);
return sresult;
}
public String getPageContent(String strUrl, String strPostRequest, int maxLength) {
// 读取结果网页
StringBuffer buffer = new StringBuffer();
try {
URL newUrl = new URL(strUrl);
HttpURLConnection hConnect = (HttpURLConnection) newUrl.openConnection();
hConnect.setReadTimeout(Integer.parseInt(sysConf.getValue("TIME_OUT")));
// POST方式的额外数据
if (strPostRequest.length() > 0) {
hConnect.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(hConnect.getOutputStream());
out.write(strPostRequest);
out.flush();
out.close();
}
// 读取内容
BufferedReader rd = new BufferedReader(new InputStreamReader(hConnect.getInputStream(), "utf-8"));
int ch;
for (int length = 0; (ch = rd.read()) > -1 && (maxLength <= 0 || length < maxLength); length++)
buffer.append((char) ch);
rd.close();
hConnect.disconnect();
return buffer.toString().trim();
} catch (Exception e) {
logger.info("对方主动关闭socket连接,放弃抓取--" );//+ e.getMessage(), e);
//e.printStackTrace();
return "";
}
}
分享到:
相关推荐
python抓取网页数据入门知识,资料来源于网上共享
网页抓包数据分析工具
arm下抓包工具 Linux version 4.14
运用正则抓取网页数据
抓网页数据包工具,让你分析网页数据的信息内容
httpwatch 9.3中文破解版(网页抓包数据分析工具) .rar
HttpWatch是强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功能.报告输出.HttpWatch 是一款能够收集并显示页页深层信息的...
HttpWatch强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST数据和目录管理功能.报告输出 HttpWatch是一款能够收集并显示页页深层信息的软件...
HttpWatch 是一款强大的网页数据分析工具,可以集成在Internet Explorer工具栏. 包括: 网页摘要;Cookies管理;缓存管理;消息头发送/接受;字符查询;POST 数据和目录管理功能;报告输出 HttpWatch 是一款能够...
很好的用R语言抓网上数据。主要用于金融研究,下载各金融市场数据。
实现从网页上抓取数据.实现从网页上抓取数据.实现从网页上抓取数据.
HttpWatch是强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功能.报告输出.HttpWatch 是一款能够收集并显示深层信息的软件...
可修改后台服务器网页达到抓包、封包、发包。
HttpWatch是强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功能.报告输出.HttpWatch 是一款能够收集并显示深层信息的软件...
C#post登陆然后进行提交抓数据
Private Declare Function ShellExecute Lib "shell32.dll" Alias _ "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ...
抓取网页数据部分函数,如:getProperty()
这个项目包含了网络抓包以及网络发包。采用的java的httpurlconnection方式实现。 并将post及get方法进行了封装,能够比较简单的调用。这里发出我自己写的源码。 在文件里面,数据的抓取为正则表达式方式抓取数据 ...
抓包工具,浏览网页时,同步打开抓包工具,可以实时查看网络数据请求
一个用C#编写的网页爬虫,抓下的内容保存在ACCESS数据库中。