Get examples of Web page data

Source: Internet
Author: User

Recently, 1 yuan shopping compared to the fire, this crowdfunding form of shopping, the buyer at a very small cost, you can get a favorite items. Some people say it is a scam, and there are people who are flocking to shopping on it every day, here do not comment. NetEase also do this mode, the name is 1 Yuan Cloud purchase, 1 Yuan treasure.

NetEase Cloud Purchase www.1yyg.com site on the top of a cumulative number of participants in the statistics, this is more curious, think of a time period to participate in the changes in the number of participants.

  

Open the site, load the page, open debugging, view the network, and note the repeated requests:

The above-mentioned request is constantly sent, and the real-time changes on the Web page accumulate statistics on the number of participants, so that the request is determined.

After opening the URL for this request:

This is obviously a jsonp, so try to get it on the webpage, every 1s clock is displayed:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> li{list-style-Type:none;} </style> &LT;TITLE&GT;JSONP Test Example </title> <script src= "Http://apps.bdimg.com/libs/jquery/2.1.1/jquer Y.js "></script> <script type=" Text/javascript ">jQuery (document). Ready (function(){      //defining the GetData () function        functionGetData () {$.ajax ({type:"Get", Async:false, URL:"Http://api.1yyg.com/JPData?action=totalBuyCount", DataType:"Jsonp", Jsonp:"Fun", Jsonpcallback:"Jsonp", Success:function(data) {varhtml = ' '; HTML+ = ' <li> ' +data[' count ']+ ' </li> '; $("#remote"). append (HTML); }, Error:function() {alert (' Fail ');            }             }); } setinterval (GetData,1000);//executes the GetData function every second.      }); </script> The remote data is as follows:<br/> <div id= "remote" ></div> </body> 

Effect:

  

You can find the rules, not 5 minutes in the background update.

Of course, you can use Java to crawl the Web page in this data way.

  

Package Worktest;import Java.io.file;import java.io.filewriter;import java.io.ioexception;import Java.net.URL; Import Java.text.simpledateformat;import java.util.date;import Java.util.scanner;import Java.util.Timer;import      Java.util.timertask;public class TaskDemo1 {public static void main (String [] args) {timertask task = new TimerTask () {        @Override public void Run () {fn ();      SYSTEM.OUT.PRINTLN ("Hello!!!");  }    };  Long delay = 0;  Long Period = 60 * 1000;  Timer timer = new timer (); Timer.scheduleatfixedrate (task, delay, Period);} public static void Fn () {File File = new file ("E:\\data\\data.txt"); FileWriter FW = NULL; String str = NULL; String s = null;  SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");//Set date format string S1 = Df.format (new date ()) + ""; try {URL url = new URL ("http://api.1yyg.com/JPData?action=totalBuyCount&fun=jsonp1456738798703&_=1456738803768"); Scanner in = new Scanner (Url.openstream ()), while (In.hasnextline ()) {str = iN.nextline (); string[] S2 =str.split (":"); string[] S3 = S2[2].split (","); String s4 = s3[0]; s = S1 +s4+ "\ r \ n";} FW = new FileWriter (file, True); Fw.write (s);} catch (Exception e) {System.out.println (e.tostring ()),} finally {if (fw! = null) try {fw.close ();} catch (IOException e) {T Hrow New RuntimeException ("Shutdown failed! ");}}}}

After the data has been obtained, it can be analyzed.

If there is a violation of the 1 Yuan Cloud purchase, please contact me, I will promptly delete!

Get examples of Web page data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.