java表单类爬虫
public static void PostForm() throws IOException {
// 2. 设置表单参数
List<NameValuePair> kv = new ArrayList<>();
kv.add(new BasicNameValuePair("column", "szse_gem_latest"));
kv.add(new BasicNameValuePair("pageNum", "1"));
kv.add(new BasicNameValuePair("pageSize", "30"));
kv.add(new BasicNameValuePair("sortName", ""));
kv.add(new BasicNameValuePair("sortType", ""));
kv.add(new BasicNameValuePair("clusterFlag", "true"));
// 3. 创建HttpPost实例
HttpPost httpPost = new HttpPost("http://www.cninfo.com.cn/new/disclosure");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36");
// 4. 让Post携带表单参数
httpPost.setEntity(new UrlEncodedFormEntity(kv, Consts.UTF_8));
// 5. 获取HttpResponse响应
CloseableHttpResponse response = httpClient.execute(httpPost);
// 6. 读response
System.out.println(EntityUtils.toString(response.getEntity()));
// 7. 释放资源
response.close();
httpClient.close();
}