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


Java Connection.timeout方法代碼示例

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


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

示例1: saveToFile

import org.jsoup.Connection; //導入方法依賴的package包/類
public static File saveToFile(String address, String localFileName) throws IOException {
    File       file       = new File(localFileName);
    Connection connection = Jsoup.connect(address).ignoreContentType(true).ignoreHttpErrors(true);
    connection.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
    connection.timeout(10000);
    Connection.Response resultImageResponse = connection.execute();
    FileOutputStream    out                 = (new FileOutputStream(file));
    out.write(resultImageResponse.bodyAsBytes());           // resultImageResponse.body() is where the image's contents are.
    out.close();
    return file;
}
 
開發者ID:thangbn,項目名稱:Direct-File-Downloader,代碼行數:12,代碼來源:HttpUtils.java

示例2: 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

示例3: timeout

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test public void timeout() {
    Connection con = HttpConnection.connect("http://example.com/");
    con.timeout(1000);
    assertEquals(1000, con.request().timeout());
}
 
開發者ID:cpusoft,項目名稱:common,代碼行數:6,代碼來源:HttpConnectionTest.java

示例4: 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

示例5: 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


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