-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTreasHTML.java
More file actions
72 lines (58 loc) · 1.83 KB
/
getTreasHTML.java
File metadata and controls
72 lines (58 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package getRiskfreeRates;
import java.io.IOException;
import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class getTreasHTML
{
private String treasuryRateURL="";
public getTreasHTML()
{
System.out.println("==in getTreasHTML Constructor ==");
}
public String getTreasuryRateURL() {
return treasuryRateURL;
}
public static void main(String[] args)
{
getTreasHTML gt = new getTreasHTML();
gt.getTreasHTMLLink();
}
public void getTreasHTMLLink()
{
System.out.println("Enter getTreasHTMLLink()");
Document doc;
try {
// get the URL reference for the current treasury rate XML
String tmpUrl ="https://www.treasury.gov/resource-center/data-chart-center/interest-rates";
tmpUrl+="/Pages/TextView.aspx?data=yield";
System.out.println("CALLING with URL="+tmpUrl);
doc = Jsoup.connect(tmpUrl).timeout(90*1000).get();
// get page title
String title = doc.title();
System.out.println("title : " + title);
// get all links
Elements links = doc.select("a[href]");
for (Element link : links) {
// get the value from href attribute
String tmpstr = link.attr("href").toString();
if( tmpstr.contains("http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData"))
{
String t2 = tmpstr.replaceAll(" ", "%20");
System.out.println("\nlink : " + t2);
treasuryRateURL = t2;
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Exit getTreasHTMLLink()");
}
}