當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection.get方法代碼示例

本文整理匯總了Java中org.jsoup.Connection.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.get方法的具體用法?Java Connection.get怎麽用?Java Connection.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jsoup.Connection的用法示例。


在下文中一共展示了Connection.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWebtoon

import org.jsoup.Connection; //導入方法依賴的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);
			}
		});
	}
}
 
開發者ID:kimyearho,項目名稱:WebtoonDownloadManager,代碼行數:46,代碼來源:ManualController.java

示例2: test

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test(timeout = 7500)
public void test() throws IOException {
	//FIXME 無法執行。存在405錯誤。
	Base64.Encoder encoder = Base64.getEncoder();
	Connection con = Jsoup.connect("http://localhost/api/v0/auth/check_cert")
			.data("uname", encoder.encodeToString("磷".getBytes(StandardCharsets.UTF_8)))
			.data("email", encoder.encodeToString("[email protected]".getBytes(StandardCharsets.UTF_8)))
			.data("zhihu", encoder.encodeToString("ice1000".getBytes(StandardCharsets.UTF_8)))
			.data("github", encoder.encodeToString("Ray-Eldath".getBytes(StandardCharsets.UTF_8)))
			.data("stackoverflow", encoder.encodeToString("VonC".getBytes(StandardCharsets.UTF_8)))
			.data("brief", encoder.encodeToString("測試".getBytes(StandardCharsets.UTF_8)))
			.data("introduce", encoder.encodeToString("測試lalala".getBytes(StandardCharsets.UTF_8)))
			.timeout(8000);
	Document doc = con.get();
	System.out.println(doc.text());
}
 
開發者ID:ProgramLeague,項目名稱:strictfp-back-end,代碼行數:17,代碼來源:CheckCert.java

示例3: test

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test(timeout = 6000)
public void test() throws IOException {
	Connection con = Jsoup.connect("http://localhost/api/v0/misc/safecheck").data("url",
			Base64.getEncoder().encodeToString("http://www.alphamedical02.fr/".
					getBytes(StandardCharsets.UTF_8)))
			.timeout(8000);
	Document doc = con.get();
	assertEquals(doc.text(),"{\"data\":{\"en\":{\"buttons\":[\"Back\",\"Continue with a fully compreh" +
			"ension about the risks originated from this action\"],\"message\":\"The external link you're w" +
			"illing to access is considered dangerous by the ZeuS Tracker or Malware Domain List, and the de" +
			"velopers team cannot be certain about the safety of the source of the link.\\nWe won't take " +
			"any responsibility of the influence caused by continuing accessing this link. You may choose to " +
			"stop accessing and be navigated back to our site or continue accessing, but the risks originated" +
			" from this action would be considered on your own.\\nWARNING: The website you're willing to access" +
			" has been considered harmful by ZeuS Tracker or Malware Domain List.\"},\"zh_CN\":{\"buttons\":" +
			"[\"返回\",\"我已了解此行為所帶來的風險並繼續 \"],\"message\":\"此外鏈已被ZeuS Tracker或Malware Domain L" +
			"ist標注為危險網站,且開發團隊無法保證此網站的安全性。\\n我們對繼續訪問此危險網站所致的後果不承擔任何責任,您可以" +
			"選擇返回或繼續訪問,但這將意味著您必須承擔此行為所帶來的風險。\\n警告:您所訪問的網站已被ZeuS Tracker或Malwar" +
			"e Domain List確認為危險網站。\\n\"}},\"meta\":{\"code\":\"200\",\"message\":\"hazard query success\"}}");
}
 
開發者ID:ProgramLeague,項目名稱:strictfp-back-end,代碼行數:21,代碼來源:SafeCheck.java

示例4: fetchResult

import org.jsoup.Connection; //導入方法依賴的package包/類
private WebSearchUnit fetchResult(Result result) {
    String link = result.getLink();
    try {
        Connection connection = Jsoup.connect(link);
        Proxy proxy = ProxyManager.getProxyIf();
        if (proxy != null) {
            connection.proxy(proxy);
        }
        Document doc = connection.get();
        String text = doc.body().text();
        LOG.debug("\nLink: {}, \nText: {}, \nSnippet: {}\n", link, text, result.getSnippet());
        return new WebSearchUnit(result, text);
    } catch (IOException e) {
        LOG.error("Failed to get page {}. Cause: {}", link, e.getMessage());
        return WebSearchUnit.emptyUnit();
    }
}
 
開發者ID:oxaoo,項目名稱:mingi,代碼行數:18,代碼來源:WebSearchLoader.java

示例5: getGroupsList

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
public ArrayList<Group> getGroupsList(Component c, Context context) throws IOException {
    ArrayList<Group> liste = new ArrayList<>();


    String url = c.groups_url;
    Connection conn = Jsoup.connect(url);
    Document doc = conn.get();
    for (Element e : doc.select("option[value$=.html]"))
    {
        Group groupe = new Group();
        groupe.name = e.text();
        groupe.dataSourceType = DataSourceType.CELCAT;
        groupe.dataSource = getRefactoredUrl(url)+(e.attr("value").replaceAll(".html", ".xml"));
        groupe.component = c;
        liste.add(groupe);
    }
    return liste;
}
 
開發者ID:natinusala,項目名稱:openedt,代碼行數:20,代碼來源:CelcatAdapter.java

示例6: loadParse

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * 按照規則,加載解析html
 * @param url		:加載URL
 * @param paramMap	:請求參數
 * @param cookieMap	:請求cookie
 * @param ifPost	:是否使用post請求
 * @param tagMap	:解析規則[0-選擇器方式、1-id方式、2-class方式、3-tag]
 * @return
 */
public static Elements loadParse(String url, Map<String, String> paramMap, Map<String, String> cookieMap,
        boolean ifPost, Map<Integer, Set<String>> tagMap) {
    if (!isUrl(url)) {
        return null;
    }
    try {
        // 請求設置
        Connection conn = Jsoup.connect(url);
        conn.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
        if (paramMap != null && !paramMap.isEmpty()) {
            conn.data(paramMap);
        }
        if (cookieMap != null && !cookieMap.isEmpty()) {
            conn.cookies(cookieMap);
        }
        conn.timeout(5000);

        // 發出請求
        Document html = null;
        if (ifPost) {
            html = conn.post();
        } else {
            html = conn.get();
        }

        // 過濾元素
        Elements resultAll = new Elements();
        if (tagMap != null && !tagMap.isEmpty()) {
            for (Entry<Integer, Set<String>> tag : tagMap.entrySet()) {
                int tagType = tag.getKey();
                Set<String> tagNameList = tag.getValue();
                if (tagNameList != null && tagNameList.size() > 0) {
                    for (String tagName : tagNameList) {
                        if (tagType == 0) {
                            Elements resultSelect = html.select(tagName);	// 選擇器方式
                            resultAll.addAll(resultSelect);
                        } else if (tagType == 1) {
                            Element resultId = html.getElementById(tagName);	// 元素ID方式
                            resultAll.add(resultId);
                        } else if (tagType == 2) {
                            Elements resultClass = html.getElementsByClass(tagName);	// ClassName方式
                            resultAll.addAll(resultClass);
                        } else if (tagType == 3) {
                            Elements resultTag = html.getElementsByTag(tagName);	// html標簽方式
                            resultAll.addAll(resultTag);
                        }
                    }
                }

            }

        } else {
            resultAll = html.getElementsByTag("body");
        }
        return resultAll;
    } catch (IOException e) {
        logger.error("", e);
    }

    return null;
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:71,代碼來源:JsoupUtil.java

示例7: fetchHandlesXml

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test
public void fetchHandlesXml() throws IOException {
    // should auto-detect xml and use XML parser, unless explicitly requested the html parser
    String xmlUrl = "http://direct.infohound.net/tools/parse-xml.xml";
    Connection con = Jsoup.connect(xmlUrl);
    Document doc = con.get();
    Connection.Request req = con.request();
    assertTrue(req.parser().getTreeBuilder() instanceof XmlTreeBuilder);
    assertEquals("<xml> <link> one </link> <table> Two </table> </xml>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
 
開發者ID:cpusoft,項目名稱:common,代碼行數:11,代碼來源:UrlConnectTest.java

示例8: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected String[] doInBackground(Void... params) {
    Log.d(TAG, "Fetching sync details");

    try {
        // Fetch the Giveaway page

        Connection jsoup = Jsoup.connect("https://www.steamgifts.com/account/profile/sync")
                .userAgent(Constants.JSOUP_USER_AGENT)
                .timeout(Constants.JSOUP_TIMEOUT)
                .cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
        Document document = jsoup.get();

        SteamGiftsUserData.extract(fragment.getContext(), document);

        // Fetch the xsrf token
        Element xsrfToken = document.select("input[name=xsrf_token]").first();
        Element lastSyncTime = document.select(".form__sync-data .notification").first();
        if (xsrfToken != null) {
            return new String[]{xsrfToken.attr("value"), lastSyncTime == null ? null : lastSyncTime.text()};
        }
    } catch (Exception e) {
        Log.e(TAG, "Error fetching URL", e);
    }
    return null;
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:27,代碼來源:SyncFragment.java

示例9: parse

import org.jsoup.Connection; //導入方法依賴的package包/類
public Link parse() throws IOException {
    Link parent = null;

    do {
        visited.add(startUrl);

        Connection con = Jsoup.connect(startUrl).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");
        Document doc = con.get();

        Element head = doc.getElementById("firstHeading");
        Link current = new Link(startUrl, head.text());

        current.parent = parent;
        parent = current;

        Elements links = doc.getElementById("bodyContent").select("a[href]");

        for(Element link : links) {
            String url = link.absUrl("href");

            if(url.startsWith("https://en.wikipedia.org/wiki/") && url.lastIndexOf(":") == 5 && !url.contains("#")) {
                if(url.equals("https://en.wikipedia.org/wiki/Philosophy")) {
                    Link phil = new Link("https://en.wikipedia.org/wiki/Philosophy", "Philosophy");
                    phil.parent = parent;

                    return phil;
                }

                if(!visited.contains(url))
                    toVisit.add(url);
            }
        }

        startUrl = toVisit.poll();
    } while(!toVisit.isEmpty());

    return null;
}
 
開發者ID:nikmanG,項目名稱:DailyProgrammer,代碼行數:39,代碼來源:WebParser.java

示例10: load

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * 加載頁麵
 *
 * @param pageLoadInfo
 *
 * @return
 */
public static Document load(PageLoadInfo pageLoadInfo) {
    if (!UrlUtil.isUrl(pageLoadInfo.getUrl())) {
        return null;
    }
    try {
        // 請求設置
        Connection conn = Jsoup.connect(pageLoadInfo.getUrl());
        if (pageLoadInfo.getParamMap() != null && !pageLoadInfo.getParamMap().isEmpty()) {
            conn.data(pageLoadInfo.getParamMap());
        }
        if (pageLoadInfo.getCookieMap() != null && !pageLoadInfo.getCookieMap().isEmpty()) {
            conn.cookies(pageLoadInfo.getCookieMap());
        }
        if (pageLoadInfo.getHeaderMap()!=null && !pageLoadInfo.getHeaderMap().isEmpty()) {
            conn.headers(pageLoadInfo.getHeaderMap());
        }
        if (pageLoadInfo.getUserAgent()!=null) {
            conn.userAgent(pageLoadInfo.getUserAgent());
        }
        if (pageLoadInfo.getReferrer() != null) {
            conn.referrer(pageLoadInfo.getReferrer());
        }
        conn.timeout(pageLoadInfo.getTimeoutMillis());

        // 代理
        if (pageLoadInfo.getProxy() != null) {
            conn.proxy(pageLoadInfo.getProxy());
        }

        // 發出請求
        Document html = null;
        if (pageLoadInfo.getIfPost()) {
            html = conn.post();
        } else {
            html = conn.get();
        }
        return html;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
 
開發者ID:xuxueli,項目名稱:xxl-crawler,代碼行數:50,代碼來源:JsoupUtil.java

示例11: getDocument

import org.jsoup.Connection; //導入方法依賴的package包/類
public static Document getDocument(String url, boolean loginCoolApk) throws IOException {
    if (!url.startsWith("https://") || !url.startsWith("http://"))
        url = "http://" + url;
    Connection connection = Jsoup.connect(url);
    if (loginCoolApk) {
        connection.cookies(new UserSave().buildWebRequestCookie());
    }
    return connection.get();
}
 
開發者ID:TaRGroup,項目名稱:CoolApk-Console,代碼行數:10,代碼來源:JsoupUtil.java

示例12: test

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test
@TestOnly
public void test() throws IOException {
	Connection con = Jsoup.connect("http://strictfp.duapp.com/timeline")
			.data("start", "2017-01-01")
			.data("end", "2017-01-02").timeout(8000);
	Document doc = con.get();
	System.out.println(doc.text());
}
 
開發者ID:ProgramLeague,項目名稱:strictfp-back-end,代碼行數:10,代碼來源:TimeLine.java

示例13: test

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test
@TestOnly
public void test() throws IOException {
	Connection con = Jsoup.connect("http://localhost:40000/api/v0/user").data("name", "\"Eldath\"").timeout(80000);
	Document doc = con.get();
	System.out.println(doc.text());
}
 
開發者ID:ProgramLeague,項目名稱:strictfp-back-end,代碼行數:8,代碼來源:User.java

示例14: get

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * Gets the HTML source of a web page.
 * 
 * @param url The URL to scrape.
 * @return A JSoup Document representing the page scraped.
 */
public static Document get(String url) {
	try {
		// before downloading the page, wait for the min delay to pass
		if (timer == null) {
			updateMinDelay();
		} else {
			synchronized (timer) {
				timer.wait();
			}
		}
		
		Connection conn = Jsoup.connect(url);
		
		if (Settings.USE_AUTH && Settings.AUTH_COOKIE != null) {
			// to log in, we need two cookies from the user, called "a" and "b" by FA.
			
			//find cookie A
			Matcher m = Pattern.compile("a=([a-fA-F0-9\\-]+)").matcher(Settings.AUTH_COOKIE);
			if (m.find()) {
				String a = m.group(1);
				conn = conn.cookie("a", a);
			}
			
			//find cookie B
			m = Pattern.compile("b=([a-fA-F0-9\\-]+)").matcher(Settings.AUTH_COOKIE);
			if (m.find()) {
				String b = m.group(1);
				conn = conn.cookie("b", b);
			}
		}
		return conn.get();
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:ThatGreyDragon,項目名稱:who2comm,代碼行數:43,代碼來源:ConnectionManager.java

示例15: getWeather

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
public Weather getWeather() throws IOException {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    String main = "https://gismeteo.com";

    Connection connection = Jsoup.connect(main).timeout(5000);
    Document document = connection.get();
    Element temp = document.getElementsByClass("temp").get(0);
    String current_temperature = temp.getElementsByClass("c").text();
    boolean belowZero = current_temperature.charAt(0) != '0' && current_temperature.charAt(0) != '+';
    current_temperature = current_temperature.substring(1, current_temperature.length() - 2);
    if (current_temperature.isEmpty())
        current_temperature = "0";
    String measurements = temp.getElementsByClass("meas").get(0).text();
    String conditionStr = document.getElementsByClass("cloudness").first().getElementsByTag("td").text();


    connection = Jsoup.connect(document.getElementsByClass("fcast").select("a").attr("abs:href"));
    document = connection.get();
    temp = document.getElementsByClass("swtab").first().getElementsByClass("temp").get(0);
    String high_temperature = " " + temp.getElementsByClass("c").get(1).text() + measurements.substring(0, 1);
    String low_temperature = " " + temp.getElementsByClass("c").get(0).text() + measurements.substring(0, 1);

    WeatherCondition condition = WeatherCondition.condition(conditionStr);

    return new Weather(condition, belowZero, current_temperature, high_temperature, low_temperature, measurements);
}
 
開發者ID:YanDoroshenko,項目名稱:Klok,代碼行數:30,代碼來源:GismeteoParser.java


注:本文中的org.jsoup.Connection.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。