pom.xml
代码源码4.0.0 org.example Spider 1.0-SNAPSHOT net.sourceforge.htmlunit htmlunit 2.49.1 com.alibaba fastjson 1.2.76 commons-io commons-io 2.8.0 8 8
package spider;
import com.alibaba.fastjson.JSONObject;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class Spider_List {
public static void main(String[] args) throws IOException {
WebClient webClient = new WebClient(BrowserVersion.CHROME);
String url = "http://26.push2.eastmoney.com/api/qt/clist/get?" +
"pn=1" +
"&pz=5000" +
"&po=0" +
"&np=1" +
"&fltt=2" +
"&invt=2" +
"&fid=f12" +
"&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23" +
"&fields=f12,f13";
String json = webClient.getPage(url).getWebResponse().getContentAsString();
Object[] objects = JSONObject.parseObject(json).getJSONObject("data").getJSONArray("diff").toArray();
for (Object object : objects) {
String F12 = JSONObject.parseObject(object.toString()).getString("f12");
String F13 = JSONObject.parseObject(object.toString()).getString("f13");
String url1 = "http://12.push2his.eastmoney.com/api/qt/stock/kline/get?secid=" + F13 + "." + F12 + "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=60&fqt=0&end=20500101&lmt=120";
String json2 = webClient.getPage(url1).getWebResponse().getContentAsString();
System.out.println(json2);
FileUtils.writeStringToFile(new File("C:\Users\LN\Desktop\data_60.csv"), json2 + "n", "UTF-8", true);
}
System.out.println("总共" + objects.length + "条数据");
}
}



