use of org.jsoup.Connection in project Tusky by Vavassor.
the class ParserUtils method parsePageHeaderInfo.
// parse the HTML page
private HeaderInfo parsePageHeaderInfo(String urlStr) throws Exception {
Connection con = Jsoup.connect(urlStr);
HeaderInfo headerInfo = new HeaderInfo();
con.userAgent(HttpConnection.DEFAULT_UA);
Document doc = con.get();
// get info
String text;
Elements metaOgTitle = doc.select("meta[property=og:title]");
if (metaOgTitle != null) {
text = metaOgTitle.attr("content");
} else {
text = doc.title();
}
String imageUrl = null;
Elements metaOgImage = doc.select("meta[property=og:image]");
if (metaOgImage != null) {
imageUrl = metaOgImage.attr("content");
}
// set info
headerInfo.baseUrl = urlStr;
if (!TextUtils.isEmpty(text)) {
headerInfo.title = QUOTE + text.toUpperCase() + QUOTE;
}
if (!TextUtils.isEmpty(imageUrl)) {
headerInfo.image = (imageUrl);
}
return headerInfo;
}
use of org.jsoup.Connection in project SmartCampus by Vegen.
the class MoreNewsPresenter method getNewsList.
@Override
public void getNewsList(int page, String url, int newsType, String view_state, String view_state_generator, String event_validation) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Connection connection = Jsoup.connect(url);
connection.data("__EVENTARGUMENT", "");
connection.data("__EVENTTARGET", "PageNavigator1$LnkBtnNext");
connection.data("__EVENTVALIDATION", event_validation);
connection.data("__VIEWSTATE", view_state);
connection.data("__VIEWSTATEGENERATOR", view_state_generator);
connection.data("Date", "30");
connection.data("tags", "");
Document document = connection.post();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
// 下一页的参数
String __VIEWSTATE = body.select("#__VIEWSTATE").first().attr("value").trim();
String __VIEWSTATEGENERATOR = body.select("#__VIEWSTATEGENERATOR").first().attr("value").trim();
String __EVENTVALIDATION = body.select("#__EVENTVALIDATION").first().attr("value").trim();
Map<String, String> newsForm = new HashMap<>();
newsForm.put("__VIEWSTATE", __VIEWSTATE);
newsForm.put("__VIEWSTATEGENERATOR", __VIEWSTATEGENERATOR);
newsForm.put("__EVENTVALIDATION", __EVENTVALIDATION);
// 本页的数据
Element photoList = body.getElementById("ListNews").getElementById("leftbox").getElementById("photolist");
List<News> newsList = getTagNews(photoList, newsType);
if (mView != null) {
mView.nextNewsListForm(newsForm);
mView.showNewsList(newsList);
mView.hideLoading(false);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
mView.loadMoreFail();
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
Aggregations