-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestScraper.java
More file actions
25 lines (21 loc) · 966 Bytes
/
TestScraper.java
File metadata and controls
25 lines (21 loc) · 966 Bytes
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
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class TestScraper {
public static void main(String[] args) throws Exception {
Document doc = Jsoup.connect("https://www.cagdaskocaeli.com.tr")
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
.timeout(25000)
.get();
System.out.println("Doc Title: " + doc.title());
Elements links = doc.select("a[href*=\"/haber/\"]");
System.out.println("Found links: " + links.size());
for(Element link : links) {
String href = link.attr("href");
String title = link.attr("title");
if (title == null || title.isBlank()) title = link.text();
System.out.println("Href: " + href + " | Title: " + title);
}
}
}