use of org.jsoup.select.Elements in project SmartCampus by Vegen.
the class ArticleDetailPresenter method getNewsContent.
@Override
public void getNewsContent(String url) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Document document = Jsoup.connect(url).get();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
// 带有href属性的a元素
Elements links = body.select("a[href]");
for (Element element : links) {
element.attr("href", "");
}
Element author = body.select("#author").first();
Element contentbody = body.select("#contentbody").first();
Element showtag = body.select("#showtag").last();
if (mView != null) {
mView.showNewsContent("</br>" + (author.html() + contentbody.html() + showtag.html()).replace("font-size: 10.5pt", "font-size: 16.5pt").replace("FONT-SIZE: 10.5pt", "FONT-SIZE: 16.5pt").replace("src=\"/files", "src=\"" + Url.ROOT_URL + "/files").replace("href=\"\"", "").replace("【点击:", "【点击:" + SystemUtils.getRandom(5, 30)).replace("发布时间", "</br>发布时间"));
mView.hideLoading(false);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
use of org.jsoup.select.Elements in project SmartCampus by Vegen.
the class MoreNewsPresenter method getTagNews.
private List<News> getTagNews(Element photoList, int type) {
List<News> newsList = new ArrayList<>();
Elements photodiv = photoList.getElementsByTag("div").select("#photodiv");
String text = "";
for (Element link : photodiv) {
Elements photoLink = link.getElementById("photo").getElementsByTag("a");
Element newsElement = photoLink.get(0);
String title = newsElement.attr("title");
String url = newsElement.attr("href");
String pic = newsElement.getElementsByTag("img").get(0).attr("src");
String date = link.getElementById("title").ownText();
text += title + "\n" + url + "\n" + pic + "\n" + date.substring(1, date.length() - 1) + "\n";
News news = new News(type, title, pic, url, date.substring(1, date.length() - 1));
newsList.add(news);
}
LogUtils.e("HomePresenter", type + "\n" + text);
return newsList;
}
use of org.jsoup.select.Elements in project SmartCampus by Vegen.
the class HomePresenter method getTagNews.
private List<News> getTagNews(Element photoList, String tag, int type) {
List<News> newsList = new ArrayList<>();
Element focusNews = photoList.getElementById(tag);
Elements focusLinks = focusNews.getElementsByTag("div").select("#photodiv");
String text = "";
for (Element link : focusLinks) {
Elements photoLink = link.getElementById("photo").getElementsByTag("a");
Element newsElement = photoLink.get(0);
String title = newsElement.attr("title");
String url = newsElement.attr("href");
String pic = newsElement.getElementsByTag("img").get(0).attr("src");
String date = link.getElementById("title").ownText();
text += title + "\n" + url + "\n" + pic + "\n" + date.substring(1, date.length() - 1) + "\n";
News news = new News(type, title, pic, url, date.substring(1, date.length() - 1));
newsList.add(news);
}
LogUtils.e("HomePresenter", type + "\n" + text);
return newsList;
}
use of org.jsoup.select.Elements in project flow by vaadin.
the class BootstrapHandlerDependenciesTest method assertCssElementLoadedEagerly.
private void assertCssElementLoadedEagerly(Element head, String url) {
Elements cssLinks = head.getElementsByAttributeValue("href", url);
assertEquals(1, cssLinks.size());
Element linkElement = cssLinks.get(0);
assertEquals("link", linkElement.tagName());
assertEquals("text/css", linkElement.attr("type"));
assertEquals(url, linkElement.attr("href"));
}
use of org.jsoup.select.Elements in project flow by vaadin.
the class BootstrapHandlerDependenciesTest method assertHtmlElementLoadedEagerly.
private void assertHtmlElementLoadedEagerly(Element head, String url) {
Elements cssLinks = head.getElementsByAttributeValue("href", url);
assertEquals(1, cssLinks.size());
Element linkElement = cssLinks.get(0);
assertEquals("link", linkElement.tagName());
assertEquals("import", linkElement.attr("rel"));
assertEquals(url, linkElement.attr("href"));
}
Aggregations