67,512
社区成员
发帖
与我相关
我的任务
分享
String excelurlString = "http://gyl.nhd-mart.com/Order.aspx?Type=wsdhd";
BasicHttpPostProcessor excelPost = null;
String[] viewState = fetchViewStateByUrl(excelurlString);
byte[] excel = new byte[1024];
int m = 0;
try
{
Map<String , String> excelMap = new HashMap<String , String>();
excelMap.put("__EVENTARGUMENT" , "");
excelMap.put("__EVENTTARGET" , "");
excelMap.put("__EVENTVALIDATION" , viewState[1]);
excelMap.put("__PREVIOUSPAGE" , "dWz7EpRiTzwPvM9i7u_z2A2");
excelMap.put("__VIEWSTATE" , viewState[0]);
excelMap.put("ctl00$ContentPlaceHolder1$btnExcel" , "µ¼³öExcel");
for(int i = 0 ; i < amount ; i++)
{
excelMap.put(valueList.get(m) , valueList.get(m+1));
m = m + 2;
}
excelMap.put("ctl00$ContentPlaceHolder1$PageNavigation1$txtPageIndex" , String.valueOf(index));
excelMap.put("ctl00$ContentPlaceHolder1$PageNavigation1$txtPageSize" , "50");
excelPost = new BasicHttpPostProcessor(getHttpclient() , excelurlString , excelMap);
HttpResponse response = excelPost.sendPost();
excel = EntityUtils.toString(response.getEntity()).getBytes();
}
catch(Exception e)
{
if(excelPost != null)
{
excelPost.cancel();
}
e.printStackTrace();
throw new MessageException("抓取失败!");
}
finally
{
if(excelPost != null)
{
excelPost.close();
}
}
String excelurlString = "http://gyl.nhd-mart.com/Order.aspx?Type=wsdhd";
BasicHttpPostProcessor excelPost = null;
String[] viewState = fetchViewStateByUrl(excelurlString);
byte[] excel = new byte[1024];
InputStream inputStream = null;
String excelcontentString = "";
int m = 0;
int len = 0;
try
{
Map<String , String> excelMap = new HashMap<String , String>();
excelMap.put("__EVENTTARGET" , "");
excelMap.put("__EVENTTARGUMENT" , "");
excelMap.put("__EVENTVALIDATION" , "");
excelMap.put("__PREVIOUSPAGE" , "dWz7EpRiTzwPvM9i7u_z2A2");
excelMap.put("__VIEWSTATE" , "");
excelMap.put("ctl00$ContentPlaceHolder1$btnExcel" , "µ¼³öExcel");
for(int i = 0 ; i < amount ; i++)
{
excelMap.put(valueList.get(m) , valueList.get(m + 1));
m = m + 2;
}
excelMap.put("ctl00$ContentPlaceHolder1$PageNavigation1$txtPageIndex" , String.valueOf(index));
excelMap.put("ctl00$ContentPlaceHolder1$PageNavigation1$txtPageSize" , "50");
excelPost = new BasicHttpPostProcessor(getHttpclient() , excelurlString , excelMap);
HttpResponse response = excelPost.sendPost();
inputStream = response.getEntity().getContent();
FileOutputStream outputStream = new FileOutputStream(new File("D:\\新华都po.xls"));
while((len = inputStream.read(excel)) != -1)
{
outputStream.write(excel , 0 , len);
}
inputStream.close();
outputStream.close();
}
catch(Exception e)
{
if(excelPost != {
excelPost.cancel();
}
e.printStackTrace();
throw new MessageException("抓取失败!");
}
finally
{
if(excelPost != null)
{
excelPost.close();
}
}