You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
718 B
25 lines
718 B
package com.example.datacollect.strategy;
|
|
|
|
import com.example.datacollect.model.Article;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.select.Elements;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class BlogStrategy implements CrawlStrategy {
|
|
@Override
|
|
public boolean supports(String url) {
|
|
return url.contains("blog.example.com");
|
|
}
|
|
|
|
@Override
|
|
public List<Article> parse(String url, Document doc) {
|
|
List<Article> articles = new ArrayList<>();
|
|
Elements titles = doc.select(".post-title");
|
|
for (Element e : titles) {
|
|
articles.add(new Article(e.text(), url, ""));
|
|
}
|
|
return articles;
|
|
}
|
|
}
|