-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBestPerformingStockScraper.java
More file actions
32 lines (26 loc) · 1.03 KB
/
BestPerformingStockScraper.java
File metadata and controls
32 lines (26 loc) · 1.03 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
import javax.swing.*;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
class BestPerformingStockScraper implements StockScraper {
private JTextArea textArea;
BestPerformingStockScraper(JTextArea textArea) {
this.textArea = textArea;
}
public void scrape() {
String url = "https://www.bankrate.com/investing/best-performing-stocks/";
try {
Document doc = Jsoup.connect(url).get();
Element bestStockTable = doc.select("table").first();
Elements tableRows = bestStockTable.select("tbody tr");
tableRows.forEach(row -> {
String companyName = row.select("td:nth-child(1)").text();
String percentChange = row.select("td:nth-child(2)").text();
textArea.append(companyName + " " + percentChange + "\n");
});
} catch (Exception e) {
e.printStackTrace();
}
}
}