Recently daughter-in-law son cervical vertebra total uncomfortable, want to hang an orthopedic on the net to look at, helpless from the nearest North XX Courtyard Orthopedic is always full. But occasionally found can have a few numbers, think of may be a temporary plus or others retreat, but also can not let me always brush it. Write a few small pieces of code ~
After a brief analysis of the contents of the registration platform, the following features were found:
-
Check the remaining number/registration required Login
-
When queried, the server uses a cookie to verify the login status, use Referer to determine the source, and non-compliant requests return to the login page or do not return any content
Package Health.guahao;import Java.awt.awtexception;import Java.awt.desktop;import java.awt.robot;import Java.awt.event.keyevent;import Java.io.ioexception;import Java.net.sockettimeoutexception;import Java.net.URI; Import Java.net.urisyntaxexception;import java.util.arraylist;import java.util.list;import org.jsoup.Connection; Import Org.jsoup.jsoup;import Org.jsoup.nodes.document;import Org.jsoup.nodes.element;import Org.jsoup.select.elements;public class Shuaguahao {static String URL = "Http://www.xxxxxphp?xxx"; public static list<string> run () throws IOException {Connection conn = jsoup.connect (URL). He Ader ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"). Header ("Accep T-encoding "," gzip, deflate, SDCH "). Header (" Accept-language "," zh-cn,zh;q=0.8,en;q=0.6 "). h Eader ("Host", "www.xxxx")//Referer must have. Header ("Referer", "Www.xxxx/ref") . Cookies ("Hm_*****af", "1*****9"). Cookies ("__c_*****9f", "e*****4"). Cookies ("__c_** HC "," f*****7 "). Cookies (" hm_*****8b "," 1*****4 "). Header (" User-agent "," mozilla/5.0 "(Wind OWS NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/40.0.2214.111 safari/537.36 "). Header (" Connection "," Ke Ep-alive "); Conn.timeout (10000); Timeout 10 sec Document doc = Conn.get (); if (doc.getallelements (). Size () < 5) {System.err.println (doc); } Elements eles = Doc.select (". GREENBG a"); if (eles! = null && eles.size () > 0) {System.out.println (eles); This List saves the number of registered pages URL, in fact, no use, because this page can not directly open list<string> List = new arraylist<string> (); for (Element ele:eles) {String uri = ele.attr ("href"); List.add (URI); } return list; } return null; public static void Main (string[] args) throws IOException, URISyntaxException, Interruptedexception, awtexception { int x = 0; for (;;) {list<string> List = null; try{list = run (); }catch (sockettimeoutexception e) {e.printstacktrace (); if (list = null) {//Open ie//String cmdstr = "cmd/c start Iexplorer" +url;// Runtime.getruntime (). exec (CMDSTR); Open the default browser//Desktop.getdesktop (). Browse (new URI (URL)); Openchrome (); } thread.sleep (10*1000); SYSTEM.OUT.PRINTLN ("Brushed" + (++x) + "Times"); }} private static void Openchrome () throws IOException, URISyntaxException, awtexception {desktop.getdeskto P (). Browse (New URI ("Http://www.baidu.com/s?wd=%E5%88%B7%E5%A5%BD%E5%BF%AB%E5%8E%BB")); Analog button Robot r = new Robot (); R.delAY (1000); R.keypress (Keyevent.vk_control); R.keypress (KEYEVENT.VK_W); R.keyrelease (Keyevent.vk_control); R.keyrelease (KEYEVENT.VK_W); R.delay (500); R.keypress (Keyevent.vk_control); R.keypress (Keyevent.vk_1); R.keyrelease (Keyevent.vk_control); R.keyrelease (Keyevent.vk_1); R.delay (500); R.keypress (KEYEVENT.VK_F5); R.keyrelease (KEYEVENT.VK_F5); }}
The program uses the Jsoup request page every 10 seconds and resolves whether it contains the corresponding elements, when found, will automatically open the default browser, where the chrome, you need to login to the first tab of Chrome registration site and go to the Department registration Inquiry page. The program will refresh automatically. I've never played AWT before, and today I find it's interesting to write some gadgets:P
This blog post is for technical exchange only, do not use this for illegal and improper use! I am not responsible for any unlawful use, ha
How to use Java to monitor the XX registration Platform x section of the available number