当前位置: 首页>>代码示例>>Java>>正文


Java Jsoup类代码示例

本文整理汇总了Java中org.jsoup.Jsoup的典型用法代码示例。如果您正苦于以下问题:Java Jsoup类的具体用法?Java Jsoup怎么用?Java Jsoup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Jsoup类属于org.jsoup包,在下文中一共展示了Jsoup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDetailContent

import org.jsoup.Jsoup; //导入依赖的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"));
    Elements elements = document.select("#big-pic img");
    Elements title = document.select("#photos h1");
    String sTitle = title.size() > 0 ? title.get(0).text() : "";
    Elements tags = document.select(".fbl a");
    List<String> tagList = new ArrayList<>();
    if (tags.size() > 0) {
        for (Element tag : tags)
            tagList.add(tag.text());
    }
    for (Element element : elements) {
        PicInfo picInfo = new PicInfo()
                .setTags(tagList)
                .setTitle(sTitle)
                .setPicUrl(element.attr("src"));
        urls.add(picInfo);
    }
    resultMap.put(DetailActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(DetailActivity.parameter.RESULT, urls);
    return resultMap;
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:25,代码来源:Aitaotu.java

示例2: getUserInfo

import org.jsoup.Jsoup; //导入依赖的package包/类
private UserInfo getUserInfo() {

        UserInfo userInfo = new UserInfo();

        try {
            Connection.Response customerInfo = Jsoup.connect(VOICEMAIL_SERVICE_URI).cookies(loadCookies()).execute();

            Document doc = customerInfo.parse();

            Elements pseudo = doc.select("input[name=pseudo]");
            Elements phoneNumber = doc.select("input[name=voip_num]");
            Elements login = doc.select("input[name=login]");
            Elements email = doc.select("input[name=email]");
            Elements uid = doc.select("input[name=uid]");

            userInfo.setPseudo((pseudo.size() > 0) ? pseudo.get(0).attr("value") : "");
            userInfo.setPhoneNumber((phoneNumber.size() > 0) ? phoneNumber.get(0).attr("value") : "");
            userInfo.setLogin((login.size() > 0) ? login.get(0).attr("value") : "");
            userInfo.setEmail((email.size() > 0) ? email.get(0).attr("value") : "");
            userInfo.setUid((uid.size() > 0) ? uid.get(0).attr("value") : "");

        } catch (IOException e) {
            e.printStackTrace();
        }
        return userInfo;
    }
 
开发者ID:bertrandmartel,项目名称:bboxapi-voicemail,代码行数:27,代码来源:VoiceMailApi.java

示例3: getDetailContent

import org.jsoup.Jsoup; //导入依赖的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"));
    Elements title = document.select("#photos h1");
    String sTitle = "";
    if (title.size() > 0)
        sTitle = title.get(0).text();

    Elements time = document.select(".tsmaincont-desc span");
    String sTime = "";
    if (time.size() > 0)
        sTime = time.get(0).text();

    Elements elements = document.select("#big-pic img");
    for (Element element : elements) {
        urls.add(new PicInfo(element.attr("src")).setTitle(sTitle).setTime(sTime));
    }

    resultMap.put(DetailActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(DetailActivity.parameter.RESULT, urls);
    return resultMap;
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:24,代码来源:Aitaotu.java

示例4: onTrackException

import org.jsoup.Jsoup; //导入依赖的package包/类
@Override
public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException err) {
	errorCount++;

	String errMessage = Jsoup.parse(StringUtils.remove(err.getMessage(), "Watch on YouTube")).text().trim();

	if(errorCount <= 3) {
		BotUtils.sendMessage(String.format(Emoji.RED_CROSS + " Sorry, %s. I'll try to play the next available song.",
				errMessage.toLowerCase()), guildMusic.getChannel());
	}

	if(errorCount == 3) {
		BotUtils.sendMessage(Emoji.RED_FLAG + " Too many errors in a row, I will ignore them until finding a music that can be played.",
				guildMusic.getChannel());
		LogUtils.infof("{Guild ID: %d} Too many errors in a row. They will be ignored until music can be played.",
				guildMusic.getChannel().getGuild().getLongID());
	}

	LogUtils.infof("{Guild ID: %d} %sTrack exception: %s",
			guildMusic.getChannel().getGuild().getLongID(), errorCount > 3 ? "(Ignored) " : "", errMessage);

	if(!guildMusic.getScheduler().nextTrack()) {
		guildMusic.end();
	}
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:26,代码来源:AudioEventListener.java

示例5: doInBackground

import org.jsoup.Jsoup; //导入依赖的package包/类
@Override
protected String doInBackground(String... strings) {
    String urlBase = strings[0];
    Document doc = null;
    try {
        String url = urlBase.startsWith("http")? urlBase : "http://" + urlBase;
        doc = Jsoup.connect(url).get();
        Elements links = doc.select("link[type=application/rss+xml]");

        if (links.size() > 0) {
            String rss_url = links.get(0).attr("abs:href");
            return rss_url;
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:21,代码来源:ReorderFeeds.java

示例6: getDocument

import org.jsoup.Jsoup; //导入依赖的package包/类
public Document getDocument(String url) {
	Document doc = null;
	try {

		doc = Jsoup.connect(url)
				.userAgent(
						"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36")
				.header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
				.header("scheme", "https").header("version", "HTTP/1.1")
				.header("accept-encoding", "gzip, deflate, sdch").header("accept-language", "zh-CN,zh;q=0.8")
				// .header("cookie", "bid=\"Q5KWZL7y8g7\";")
				.header("cache-control", "max-age=0").get();

	} catch (Exception e) {

	}
	return doc;

}
 
开发者ID:metaotao,项目名称:doubanbook,代码行数:20,代码来源:TestSpider.java

示例7: init

import org.jsoup.Jsoup; //导入依赖的package包/类
private void init(int i) {
    try {
        this.documentDefault = Jsoup.connect(league.getBaseScoreUrl() + "/scoreboard/_/group/" + i + "/date/" + DateUtils.getDatePlus("yyyyMMdd", -1))
                .timeout(60 * 1000)
                .maxBodySize(0)
                .get();
        this.document = Jsoup.connect(league.getBaseScoreUrl() + "/scoreboard/_/group/" + i + "/date/" + DateUtils.getDatePlus("yyyyMMdd", 0))
                .timeout(60 * 1000)
                .maxBodySize(0)
                .get();
        this.documentTomorrow = Jsoup.connect(league.getBaseScoreUrl() + "/scoreboard/_/group/" + i + "/date/" + DateUtils.getDatePlus("yyyyMMdd", 1))
                .timeout(60 * 1000)
                .maxBodySize(0)
                .get();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:riteshakya037,项目名称:Android-Scrapper,代码行数:19,代码来源:EspnScoreboardParser.java

示例8: createApplication

import org.jsoup.Jsoup; //导入依赖的package包/类
/**
 * Create a new OVH Application using https://eu.api.ovh.com/createApp/
 * Outout the Application Key and Application Secret in std-out
 * @param nic
 * @param password
 * @throws IOException
 */
public void createApplication(String nic, String password) throws IOException {
	String url = "https://eu.api.ovh.com/createApp/";
	Document doc = Jsoup.connect(url)
			.data("nic", nic)
			.data("password", password)
			.data("applicationName", "One Shoot Token")
			.data("applicationDescription", "One Shoot Token")
			.post();
	String body = doc.toString();
	Pattern extract = Pattern.compile(" Application (\\w+)<pre><name>([^<]+)</name></pre>");
	Matcher m = extract.matcher(body);
	String Key = null;
	String Secret = null;
	while (m.find()) {
		String k = m.group(1);
		String v = m.group(2);
		if (k.equals("Key"))
			Key = v;
		if (k.equals("Secret"))
			Secret = v;
	}
	log.warn("Key:{} Secret:{}", Key, Secret);
}
 
开发者ID:UrielCh,项目名称:ovh-java-sdk,代码行数:31,代码来源:ApiOvhUtils.java

示例9: parse

import org.jsoup.Jsoup; //导入依赖的package包/类
@Override
    public List<Proxy> parse(String content) {
        List<Proxy> proxyList = new ArrayList<>();
        if (content == null || content.equals("")){
            return proxyList;
        }
        Document document = Jsoup.parse(content);
        Elements elements = document.select("table tr:gt(1)");
        for (Element element : elements){
            String ip = element.select("td:eq(0)").first().text();
            String port  = element.select("td:eq(1)").first().text();
            String isAnonymous = element.select("td:eq(3)").first().text();
//            if(!anonymousFlag || isAnonymous.contains("匿")){
            proxyList.add(new Proxy(ip, Integer.valueOf(port), Constant.TIME_INTERVAL));
//            }
        }
        return proxyList;
    }
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:19,代码来源:Ip66ProxyListPageParser.java

示例10: parseZhihuTopics1

import org.jsoup.Jsoup; //导入依赖的package包/类
public static void parseZhihuTopics1(Page page, Result result) {
    String json = page.getContent();
    JSONObject object = JSON.parseObject(json);
    JSONArray array = object.getJSONArray("msg");
    if(array.size()==0) {
        result.setSkip(true);
        return;
    }
    for (int i = 0; i < array.size(); i++) {
        String topicStr = array.getString(i);
        Document doc = Jsoup.parseBodyFragment(topicStr);
        Element a = doc.body().select("div.item").first().select("a[target]").first();
        String href = "https://www.zhihu.com" + a.attr("href")+"/newest";
        result.addRequest(new Request(href, HttpMethod.GET));
    }
    Request request = new Request("https://www.zhihu.com/node/TopicsPlazzaListV2", HttpMethod.POST);
    JSONObject object1 = new JSONObject();
    object1.put("topic_id", page.getRequest().getAddch("topic_id"));
    object1.put("offset", Integer.valueOf(((Integer) page.getRequest().getAddch("offset")) + 20));
    object1.put("hash_id", "22e50cd21ed9df7085ff76d62175e986");
    request.addParame("method", "next")
            .addParame("params", object1.toJSONString()).addAttach("offset", Integer.valueOf(((Integer) page.getRequest().getAddch("offset")) + 20)).addAttach("topic_id", page.getRequest().getAddch("topic_id"));
    result.addRequest(request);
}
 
开发者ID:StevenKin,项目名称:ZhihuQuestionsSpider,代码行数:25,代码来源:ParseRegularUtil.java

示例11: getDetailContent

import org.jsoup.Jsoup; //导入依赖的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"));
    PicInfo picInfo = new PicInfo();
    Elements elements = document.select("#bigpic img");
    for (Element element : elements) {
        picInfo.setPicUrl(baseUrl + element.attr("src"));
    }
    Elements title = document.select("#entry h1");
    if (title.size() > 0)
        picInfo.setTitle(title.text());
    Elements tags = document.select(".postinfo a");
    if (tags.size() > 0) {
        List<String> tagList = new ArrayList<>();
        for (Element t : tags)
            tagList.add(t.text());
        picInfo.setTags(tagList);
    }
    urls.add(picInfo);

    resultMap.put(DetailActivity.parameter.CURRENT_URL, currentUrl);
    resultMap.put(DetailActivity.parameter.RESULT, urls);
    return resultMap;
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:26,代码来源:Mntu92.java

示例12: getParsedData

import org.jsoup.Jsoup; //导入依赖的package包/类
private List<Map<String, String>> getParsedData(Content content){
    List<Map<String,String >> testData = new ArrayList<>();
    JSONObject jsonObject = new JSONObject(content.toString());
    JSONObject body = (JSONObject) jsonObject.get("body");
    JSONObject storage = (JSONObject) body.get("storage");
    Document doc = Jsoup.parse(storage.get("value").toString());
    Elements tRows = doc.select("tr");
    LOG.info("Парсим данные страницы");
    for (Element row : tRows){
        HashMap<String,String> rowData = new HashMap<>();
        Elements tds = row.select("td[colspan!="+countColumns+"]");
        if (tds.size()!=0 && (!tds.get(0).text().equals(""))){
            rowData.put("dKey",tds.get(0).text());
            rowData.put("dValue",tds.get(1).text());
            rowData.put("dComment",tds.get(2).text());
            rowData.put("dHltValue",tds.get(3).text());
            rowData.put("dDevValue",tds.get(4).text());
            testData.add(rowData);
        }
        LOG.debug(row.text());
    }
    return testData;
}
 
开发者ID:asmodeirus,项目名称:BackOffice,代码行数:24,代码来源:TestDataController.java

示例13: fetchBody

import org.jsoup.Jsoup; //导入依赖的package包/类
public static void fetchBody(final String url, final Callback callback) {
  new Thread() {
    @Override
    public void run() {
      try {
        Document document = Jsoup
            .connect(url)
            .userAgent(FormatUtil.USER_AGENT_PC)
            .get();
        callback.output(document.body());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }.start();
}
 
开发者ID:tomoya92,项目名称:android-apps,代码行数:17,代码来源:JsoupUtil.java

示例14: getSafeUploadVideo

import org.jsoup.Jsoup; //导入依赖的package包/类
public String getSafeUploadVideo(String url) {
    //http://www.safeupload.org/getembed/f93fb4096e0875979215c0307dd53ff5
    String lVideoUrl = "";
    try {
        Document docdata = Jsoup.connect(url).userAgent(mUserAgent)
                .referrer("http://www.google.com")
                .timeout(Parser.getParseTimeOut()).get();
        Elements eles = docdata.select("body").select("div + script");
        if (eles != null && !eles.isEmpty()) {
            lVideoUrl = eles.get(eles.size() - 2).html();
            if (!TextUtils.isEmpty(lVideoUrl)) {
                final Pattern pattern = Pattern.compile("'file': '(.+?)'");
                final Matcher matcher = pattern.matcher(lVideoUrl);
                matcher.find();
                lVideoUrl = matcher.group(1);
            }
        }
    } catch (IOException e) {
        WriteLog.appendLog(Log.getStackTraceString(e));
    }
    return lVideoUrl;
}
 
开发者ID:SalmanTKhan,项目名称:MyAnimeViewer,代码行数:23,代码来源:Parser.java

示例15: search

import org.jsoup.Jsoup; //导入依赖的package包/类
public List<Anime> search(String query) throws IOException, InterruptedException, ExecutionException, JSONException {
    String url = "https://9anime.to/search?keyword=" + query.replace(" ", "+");
    Document doc = Jsoup.connect(url).get();
    int totalPages = 1;

    List<Anime> animes = new ArrayList<>();

    if (doc.select("div.paging").size() > 0) {
        totalPages = Math.max(Integer.parseInt(doc.select("span.total").first().text()), totalPages);
    }

    animes.addAll(parseSearchPage(doc));

    for (int i = 1; i < totalPages; ++i) {
        animes.addAll(parseSearchPage(Jsoup.connect(url + "&page=" + (i + 1)).get()));
    }

    return animes;
}
 
开发者ID:RutoTV,项目名称:9AnimeAndroid,代码行数:20,代码来源:NineAnimeApi.java


注:本文中的org.jsoup.Jsoup类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。