Jsoup HTML Collector

Source: Internet
Author: User

Package com.forex.collect;

Import java.io.IOException;
Import Java.util.HashMap;
Import Java.util.Iterator;
Import Java.util.Map;
Import Java.util.Random;

Import javax.mail.MessagingException;

Import Org.jsoup.Connection.Method;
Import Org.jsoup.Connection.Response;
Import Org.jsoup.Jsoup;
Import org.jsoup.nodes.Document;
Import org.jsoup.nodes.Element;
Import org.jsoup.select.Elements;

public class Hexuncollect {
private static final int timeout = 5 * 1000;

public static void Main (String ... args) throws IOException, Messagingexception, interruptedexception {
Hexuncollect HC = new Hexuncollect ();

while (true) {
Hc.excute ();
Thread.Sleep (Long.valueof (Hc.getrandom ()) * 1000 * 60);
}
}


public int Getrandom () {
int max = 15;
int min = 3;
Random random = new random ();
int s = random.nextint (max)% (Max-min + 1) + min;
System.out.println (s);
return s;
}

public void Excute () throws IOException, Messagingexception {
String url = "Http://quote.hexun.com/forex/forex.aspx";

Map<string, string> cookies = new hashmap<string, string> ();
Cookies.put ("__jsluid", "5942ae5f94a3c06666e2a4dfa745c94e");
Cookies.put ("__utma", "194262068.1565981099.1453342082.1453342082.1453342082.1");
Cookies.put ("__UTMC", "194262068");
Cookies.put ("__UTMZ", "194262068.1453342082.1.1.utmcsr=hexun.com|utmccn= (referral) |utmcmd=referral|utmcct=/ ");
Cookies.put ("Hxck_sq_common", "Loginstatecookie");

//Fetch the specified URL and parse to a HTML DOM
Response res = Jsoup
. Connect (URL)
. Cookies (Cookies)
. He Ader ("User-agent", "mozilla/5.0" (Windows NT 5.1; ZH-CN) applewebkit/535.12 (khtml, like Gecko) chrome/22.0.1229.79 safari/535.12 ")
. Timeout (timeout)
. Data (" Type "," 3 ")
. Method (Method.post)
. Execute ();

Document doc = Res.parse ();

Elements links = doc.select ("tr");
iterator<element> Iterator = Links.iterator ();
while (Iterator.hasnext ()) {
Element next = Iterator.next ();
String text = Next.text ();
string[] split = Text.split ("");
String enCode = split[0];
String zhcode = split[1];
String point = split[2];
String ZHANGF = split[3];
String datee = split[split.length-1];

if ("Nzdcad". Equalsignorecase (EnCode)) {
if (0.9200<=double.valueof) && double.valueof (point) <=0.92500) {
Sendmail.sendmessage (Datee, encode+ "|" +point+ "|" +zhangf+ "|" +datee);
}

System.out.println (EnCode);
System.out.println (Zhcode);
System.out.println (point);
System.out.println (ZHANGF);
}
System.out.println (datee);

}
}



}

Jsoup HTML Collector

Related Article

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.