Search in sources :

Example 61 with Elements

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));
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Element(org.jsoup.nodes.Element) DisposableHolder(com.vegen.smartcampus.baseframework.network.DisposableHolder) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 62 with Elements

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;
}
Also used : News(com.itculturalfestival.smartcampus.entity.News) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements)

Example 63 with Elements

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;
}
Also used : News(com.itculturalfestival.smartcampus.entity.News) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements)

Example 64 with Elements

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"));
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 65 with Elements

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"));
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Aggregations

Elements (org.jsoup.select.Elements)709 Element (org.jsoup.nodes.Element)490 Document (org.jsoup.nodes.Document)362 ArrayList (java.util.ArrayList)213 IOException (java.io.IOException)151 Test (org.junit.Test)110 URL (java.net.URL)58 List (java.util.List)47 Matcher (java.util.regex.Matcher)42 Pattern (java.util.regex.Pattern)34 HashMap (java.util.HashMap)30 InputStream (java.io.InputStream)29 Jsoup (org.jsoup.Jsoup)28 Configuration (com.vaadin.addon.charts.model.Configuration)27 File (java.io.File)26 JSONObject (org.json.JSONObject)26 JSONException (org.json.JSONException)25 Collectors (java.util.stream.Collectors)23 URISyntaxException (java.net.URISyntaxException)22 BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)20