本文整理汇总了Java中org.jsoup.nodes.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于org.jsoup.nodes包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWebtoon
import org.jsoup.nodes.Document; //导入依赖的package包/类
/**
* 웹툰조회
*/
public void getWebtoon(String code) {
if (!"".equals(code)) {
CommonService cs = new CommonService();
Connection conn = cs.getConnection(code);
conn.timeout(5000);
Document doc = null;
codeInputField.setText(code);
wDesc.setWrapText(true);
try {
doc = conn.get();
String title = doc.select("title").text().split("::")[0];
setTitle(title);
String author = doc.select("div.detail h2 > span").text();
wTitle.setText(title + "(" + author + ")");
String desc = doc.select("div.detail p").text();
wDesc.setText(desc);
String img = doc.select("div.thumb > a img").attr("src");
thumbnail.setImage(new Image(img, true));
} catch (Exception e) {
e.printStackTrace();
}
} else {
Platform.runLater(new Runnable() {
@Override
public void run() {
AlertSupport alert = new AlertSupport("웹툰코드를 입력하세요.");
alert.alertInfoMsg(stage);
}
});
}
}
示例2: meiyuxsCatalog
import org.jsoup.nodes.Document; //导入依赖的package包/类
private static Map meiyuxsCatalog(Map map, String url) {
try {
List data = new ArrayList();
Document document = Jsoup
.connect(url)
.userAgent(FormatUtil.USER_AGENT_PC)
.get();
Element body = document.body();
Elements catalogEles = body.getElementsByClass("list-group-item");
for (Element catalogE : catalogEles) {
if (catalogE.getElementsByTag("a").size() > 0) {
Map<String, Object> _map = new HashMap<>();
_map.put("catalog", catalogE.text());
_map.put("href", "http://www.meiyuxs.com" + catalogE.getElementsByTag("a").first().attr("href"));
data.add(_map);
}
}
map.put("data", data);
map.put("cover", "");
map.put("lastChapter", ((Map) data.get(data.size() - 1)).get("catalog").toString());
} catch (IOException e) {
e.printStackTrace();
}
return map;
}
示例3: getDetailContent
import org.jsoup.nodes.Document; //导入依赖的package包/类
@Override
public Map<DetailActivity.parameter, Object> getDetailContent(String baseUrl, String currentUrl, byte[] result, Map<DetailActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
List<PicInfo> urls = new ArrayList<>();
Document document = Jsoup.parse(new String(result, "utf-8"));
String sTitle = "";
Elements title = document.select("#header h1");
if (title.size() > 0)
sTitle = title.get(0).text();
List<String> tagList = new ArrayList<>();
Elements tags = document.select("ul.tagList a");
if (tags.size() > 0)
for (Element tag : tags)
tagList.add(tag.text());
Elements elements = document.select("ul.gallery li:has(img)");
for (Element element : elements) {
urls.add(new PicInfo(element.attr("data-src")).setTitle(sTitle).setTags(tagList));
}
resultMap.put(DetailActivity.parameter.CURRENT_URL, currentUrl);
resultMap.put(DetailActivity.parameter.RESULT, urls);
return resultMap;
}
示例4: showWord
import org.jsoup.nodes.Document; //导入依赖的package包/类
public void showWord() {
try {
String language;
Languages l;
l = (Languages) cmbLanguage.getSelectedItem();
language = l.getLang();
Document doc = Jsoup.connect("http://evilinsult.com/generate_insult.php?lang=" + language).get();
Elements links = doc.select("body");
for (Element link : links) {
txtPaneShow.setText("\n" + link.text());
}
} catch (RuntimeException e) {
throw e;
} catch (Exception ex) {
txtPaneShow.setText("\n" + "Insult Outage! Please Check Your Internet Connection And Try Again In Three Minutes");
}
}
示例5: onHandleParseHTML
import org.jsoup.nodes.Document; //导入依赖的package包/类
@Override
public void onHandleParseHTML(final String url) {
mView.showLoading(true);
Observable.create(new ObservableOnSubscribe<ArrayList<ArticleItem>>() {
@Override
public void subscribe(ObservableEmitter<ArrayList<ArticleItem>> e) throws Exception {
ArrayList<ArticleItem> list = new ArrayList<>();
Document doc = Jsoup.connect(url).get();
Elements ul = doc.getElementsByClass("list_line");
for (Element u : ul) {
Elements li = u.getElementsByTag("li");
for (Element l : li) {
String text = l.getElementsByTag("a").text();
String href = l.getElementsByTag("a").attr("href");
String time = l.getElementsByTag("span").text();
list.add(new ArticleItem(text, href, time));
}
}
e.onNext(list);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ArrayList<ArticleItem>>() {
@Override
public void accept(@NonNull ArrayList<ArticleItem> articleItems) throws Exception {
mView.showList(articleItems);
mView.showLoading(false);
}
});
}
示例6: parseToText
import org.jsoup.nodes.Document; //导入依赖的package包/类
@JSStaticFunction
public static void parseToText(final String url, final String option, final Function func) throws IOException {
new Thread(new Runnable() {
@Override
public void run() {
Document document = null;
try {
document = Jsoup.connect(url).get();
Elements element = document.select(option);
func.call(context, scope, scope, new Object[] { element.text(), null });
} catch (IOException e) {
try {
func.call(context, scope, scope, new Object[] { null, e });
} catch (Exception err) {}
}
}
}).start();
}
示例7: getURLsFromPage
import org.jsoup.nodes.Document; //导入依赖的package包/类
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<>();
for (Element thumb : doc.select("div.picture_view > div.pictures_block > div.items > div.item-container > a > div.thumb_container > div.img > img")) {
String image = thumb.attr("src");
// replace thumbnail urls with the urls to the full sized images
image = image.replaceAll(
"https://upt.xhcdn\\.",
"http://up.xhamster.");
image = image.replaceAll("ept\\.xhcdn", "ep.xhamster");
image = image.replaceAll(
"_160\\.",
"_1000.");
// Xhamster has bad cert management and uses invalid certs for some cdns, so we change all our requests to http
image = image.replaceAll("https", "http");
result.add(image);
}
return result;
}
示例8: getDocumentWithCookie
import org.jsoup.nodes.Document; //导入依赖的package包/类
/**
* 方法说明:绑定单cookie模拟浏览器,返回document对象
*
* @param url 被访问url
* @param cookieKey 绑定cookie的key
* @param cookieValue 绑定cookie的value
* @return Document 返回document对象
* @throws Exception
*/
public static Document getDocumentWithCookie(String url, String cookieKey, String cookieValue) throws Exception {
Document doc = null;
if (StringUtil.isEmpty(cookieKey) && StringUtil.isEmpty(cookieValue)) {
doc = getDocument(url);
} else if (!StringUtil.isEmpty(cookieKey) && !StringUtil.isEmpty(cookieValue)){
Map<String, String> cookiesMap = new HashMap<String, String>();
cookiesMap.put(cookieKey, cookieValue);
doc = getDocumentWithCookies(url, cookiesMap);
} else {
// parameter is error. 参数が不正である、所传参数错误。
throw new IllegalArgumentException("key or value is err"); // TODO hard coding is fixing bluetata 2017/03/20 add
}
return doc;
}
示例9: extractFromProperties
import org.jsoup.nodes.Document; //导入依赖的package包/类
public static List<MatchedDate> extractFromProperties(Document document) {
List<MatchedDate> result = Lists.newArrayList();
for (String selector : ITEMPROP_SELECTORS) {
document.select(selector).forEach(m -> {
String datetime = m.attr("datetime");
String content = m.attr("content");
String title = m.attr("title");
if (!Strings.isNullOrEmpty(datetime)) {
result.add(new MatchedDate(datetime, selector));
} else if (!Strings.isNullOrEmpty(content)) {
result.add(new MatchedDate(content, selector));
} else if (!Strings.isNullOrEmpty(title)) {
result.add(new MatchedDate(title, selector));
}
});
}
return result;
}
示例10: getContent
import org.jsoup.nodes.Document; //导入依赖的package包/类
@Override
public Map<ContentsActivity.parameter, Object> getContent(String baseUrl, String currentUrl, byte[] result, Map<ContentsActivity.parameter, Object> resultMap) throws UnsupportedEncodingException {
List<AlbumInfo> urls = new ArrayList<>();
Document document = Jsoup.parse(new String(result, "utf-8"));
Elements elements = document.select("div.album");
for (Element element : elements) {
AlbumInfo temp = new AlbumInfo();
Elements title = element.select("span.name");
if (title.size() > 0)
temp.setTitle(title.get(0).text());
Elements album = element.select(".pic_box a");
temp.setAlbumUrl(album.attr("href"));
Elements pic = album.select("img");
if (pic.size() > 0)
temp.setPicUrl(pic.get(0).attr("src"));
urls.add(temp);
}
resultMap.put(ContentsActivity.parameter.CURRENT_URL, currentUrl);
resultMap.put(ContentsActivity.parameter.RESULT, urls);
return resultMap;
}
示例11: Wikipedia
import org.jsoup.nodes.Document; //导入依赖的package包/类
static void Wikipedia(String dico) {
Document significatowikipedia = null;
String cercowikipedia = dico.substring((dico.indexOf("'")) + 1, (dico.lastIndexOf("'")));
try {
significatowikipedia = Jsoup.connect("https://it.wikipedia.org/wiki/" + cercowikipedia.replace(" ", "_")).userAgent("Mozilla").get();
String divs = significatowikipedia.select("p").text();
if (!divs.equals("")) {
new GUI().giveResponse("La ricerca di " + cercowikipedia + " su wikipedia ha restituito il seguente risultato:" + '\n' + divs);
} else {
new GUI().giveResponse("Mi dispiace, non ho trovato informazioni su " + cercowikipedia + " su Wikipedia...");
}
} catch (HttpStatusException e) {
new GUI().giveResponse("Mi dispiace, Wikipedia sembra non avere una voce per '" + cercowikipedia +"'...");
} catch (java.io.IOException f) {
f.printStackTrace();
} catch (StringIndexOutOfBoundsException g) {
new GUI().giveResponse("Ricorda che, perché io cerchi informazioni riguardo a qualcosa, occorre che tu la definisca fra due virgolette!");
}
}
示例12: testJsoupSelectorUnexpectedError
import org.jsoup.nodes.Document; //导入依赖的package包/类
/**
* Test that {@link PawpedsDocumentParser#parseSearch(Document)} throws an
* {@link IllegalArgumentException} if there is an jsoup parsing error.
*/
@Test(expected = IllegalArgumentException.class)
public void testJsoupSelectorUnexpectedError() throws Exception {
// Given
Document document = mock(Document.class);
Elements noErrorElement = mock(Elements.class);
when(noErrorElement.text()).thenReturn("");
when(document.select("th.error")).thenReturn(noErrorElement);
when(document.select("table.searchresult tr.searchresult:has(td.searchresult)")).thenThrow(SelectorParseException.class);
// When
pawpedsDocumentParser.parseSearch(document);
// Then
// the exception is expected
}
示例13: loadAnuncios
import org.jsoup.nodes.Document; //导入依赖的package包/类
public void loadAnuncios(final AnunciosCallback callback) {
UAWebService.HttpWebGetRequest(context, ANUNCIOS_URL, new UAWebService.WebCallBack() {
@Override
public void onNavigationComplete(boolean isSuccessful, String body) {
if (isSuccessful) {
Document doc = Jsoup.parse(body);
//Get Post data
Element anuncios = doc.select(ANUNCIOS_LIST_BODY).first();
try {
for (Element anuncio : anuncios.children()) {
parseAnuncio(anuncio, "");
}
callback.onResult(true, "");
} catch (NullPointerException e) {
FirebaseCrash.log(body);
FirebaseCrash.report(e);
callback.onResult(false, ErrorManager.LOGIN_REJECTED); //Usually because session ended!
}
} else {
callback.onResult(false, body);
}
}
});
}
示例14: getT
import org.jsoup.nodes.Document; //导入依赖的package包/类
@Override
public List<ImageModel> getT(Document document) {
if (view == null) {
return new ArrayList<>();
}
switch (view.getType()) {
case ApiConfig.Type.DOU_BAN_MEI_ZI:
return JsoupDoubanManager.get(document).getImageList();
case ApiConfig.Type.KK:
return JsoupKKManager.get(document).getImageList();
case ApiConfig.Type.M_ZI_TU:
return JsoupMZiTuManager.get(document).getImageList();
case ApiConfig.Type.MM:
return JsoupMMManager.get(document).getImageList();
case ApiConfig.Type.MEIZITU:
return JsoupMeiZiTuManager.get(document).getImageList();
default:
return new ArrayList<>();
}
}
示例15: getDescriptionsFromPage
import org.jsoup.nodes.Document; //导入依赖的package包/类
@Override
public List<String> getDescriptionsFromPage(Document page) {
List<String> textURLs = new ArrayList<>();
// Iterate over all thumbnails
for (Element thumb : page.select("div.zones-container span.thumb")) {
logger.info(thumb.attr("href"));
if (isStopped()) {
break;
}
Element img = thumb.select("img").get(0);
if (img.attr("transparent").equals("false")) {
continue; // a.thumbs to other albums are invisible
}
textURLs.add(thumb.attr("href"));
}
return textURLs;
}