1. Origin of the article

Know a brother, appearance level and talent both, but choose to rely on talent experience life. Forget about him, lest self-deprecation ~ ~

His thick eyebrows rose slightly, his eyes as clear as the morning dew, his nose as straight, his lips as pink as a rose petal, and his skin as clear as white. His cold, solitary eyes seemed out of focus, and his dark, dark eyes were covered with comfortable hair scattered around his ears, which gave out a faint blue light. His beauty could not help but make people secretly admire him, and there was a cold smell around him.Copy the code

As a “young” person, a lot of friends should be right fund, stock dabble somewhat, don’t talk, talk of all is loss much, this elder brother excepted!

This article is better than gourd ladle, don’t like do not spray, only for the use of learning and entertainment.

2. Data sources

The big guy has measured the depth of the river. It’s not deep… It’s taller than you and me, so… Don’t swim in the river at will. Come on. You can cross the river by this small canoe.

A small wooden boat

Scroll down to see if you wish your fund/stock list was as red as this excellent request that tells you the secret to making money.

# Original link: Provide data information to http://fund.eastmoney.com/Data/Fund_JJJZ_Data.aspx?lx=1&sort=zdf, desc&page = 2200 & onlySale = 0 # lx and clear is the type of shorthand. Sort means that sorting certain fields can be ignored. For pages 2,200 would be the second page,200 per page, and onlySale would be the condition to sell. http://fund.eastmoney.com/Data/Fund_JJJZ_Data.aspx?lx=1&sort=zdf,desc&page=2,100&onlySale=0Copy the code

If nothing else, you have to like the reference article for this link!!

3. Data capture

Now comes the headache, you have what you want, so I want to bother to give it to you.

It’s probably not that difficult for you to face the keyboard, right (ha ha ha). All it takes is an Http request to get the data we want. There are many types of Http request methods related to Java. The author uses the Http request based on the third-party open source tool class Hutool.

HttpConnection HttpConnection = httpConnection. create(url, null); InputStream inputStream = httpConnection.getInputStream(); InputStreamReader = new InputStreamReader(inputStream," utF-8 "); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String temp; while ((temp = bufferedReader.readLine()) ! = null){system.out.println (temp); HttpResponse = httprequest.get (URL).timeout(300 * 1000).setConnectionTimeout(200 *) 1000).execute(); System.out.println(httpResponse.body());Copy the code

The following data is captured as follows:

If you don’t want the data, you can use Json to parse the data.

// According to the printed result information, the result needs to be converted to the standard JSON format JSONObject JSONObject = new JSONObject(httpResponse.body().replace("var db=","")); JSONArray datas = jsonObject.getJsonArray ("datas"); List<Fund> funds = new ArrayList<>(); for (int i = 0; i < datas.length(); i++) { JSONArray jsonArray = datas.getJSONArray(i); Fund fund = new Fund(); fund.setCode(jsonArray.getString(0)); fund.setName(jsonArray.getString(1)); fund.setValue(jsonArray.getString(3)); funds.add(fund); }Copy the code

Through the above simple operation, the small canoe can swing freely in the river, you can browse the fund details list on each page.

The subsequent data can be stored in the database, according to their own needs for relevant display, but also in-depth analysis of personal collection of fund dynamic change information.

The fund code Name of the fund The latest net
005477 Changan Xinxi flexible configuration hybrid A 0.8040
005478 Changan Xinxi flexible configuration mixed C 0.7982
005343 Changan Yusheng flexible configuration hybrid A 1.1877
All things are difficult at the beginning, but now like picking apples on the shoulders of giants, relatively easy, along the direction of excellent learning, study, follow the torrent forward, the small canoe will not stop, even if we have no OARS, will also march forward in the torrent.Copy the code

【 reference article 】 juejin.cn/post/703083…