本文整理了Java中org.jsoup.Connection.timeout()
方法的一些代码示例,展示了Connection.timeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.timeout()
方法的具体详情如下:
包路径:org.jsoup.Connection
类名称:Connection
方法名:timeout
[英]Set the total request timeout duration. If a timeout occurs, an java.net.SocketTimeoutException will be thrown.
The default timeout is 30 seconds (30,000 millis). A timeout of zero is treated as an infinite timeout.
Note that this timeout specifies the combined maximum duration of the connection time and the time to read the full response.
[中]设置总请求超时持续时间。如果发生超时,则会调用java。网将抛出SocketTimeoutException。
默认超时为30秒(30000毫秒)。零超时被视为无限超时。
请注意,此超时指定连接时间和读取完整响应的时间的组合最大持续时间。
代码示例来源:origin: RipMeApp/ripme
public Http timeout(int timeout) {
connection.timeout(timeout);
return this;
}
public Http ignoreContentType() {
代码示例来源:origin: org.jsoup/jsoup
/**
Fetch a URL, and parse it as HTML. Provided for compatibility; in most cases use {@link #connect(String)} instead.
<p>
The encoding character set is determined by the content-type header or http-equiv meta tag, or falls back to {@code UTF-8}.
@param url URL to fetch (with a GET). The protocol must be {@code http} or {@code https}.
@param timeoutMillis Connection and read timeout, in milliseconds. If exceeded, IOException is thrown.
@return The parsed HTML.
@throws java.net.MalformedURLException if the request URL is not a HTTP or HTTPS URL, or is otherwise malformed
@throws HttpStatusException if the response is not OK and HTTP response errors are not ignored
@throws UnsupportedMimeTypeException if the response mime type is not supported and those errors are not ignored
@throws java.net.SocketTimeoutException if the connection times out
@throws IOException if a connection or read error occurs
@see #connect(String)
*/
public static Document parse(URL url, int timeoutMillis) throws IOException {
Connection con = HttpConnection.connect(url);
con.timeout(timeoutMillis);
return con.get();
}
代码示例来源:origin: RipMeApp/ripme
.ignoreContentType(true)
.userAgent(USER_AGENT)
.timeout(5000)
.data(postData)
.post();
代码示例来源:origin: RipMeApp/ripme
response = Jsoup.connect(updateJarURL)
.ignoreContentType(true)
.timeout(Utils.getConfigInteger("download.timeout", 60 * 1000))
.maxBodySize(1024 * 1024 * 100)
.execute();
代码示例来源:origin: ChinaSilence/any-video
public static Document getDocWithPC(String url) {
try {
return Jsoup.connect(url).userAgent(UA_PC).timeout(TIME_OUT).ignoreContentType(true).get();
} catch (IOException e) {
log.error(ERROR_DESC + url);
throw new AnyException(ERROR_DESC + url);
}
}
代码示例来源:origin: RipMeApp/ripme
private String getImageLinkFromDLLink(String url) {
try {
Connection.Response response = Jsoup.connect(url)
.userAgent(USER_AGENT)
.timeout(10000)
.cookies(cookies)
.followRedirects(false)
.execute();
String imageURL = response.header("Location");
LOGGER.info(imageURL);
return imageURL;
} catch (IOException e) {
LOGGER.info("Got error message " + e.getMessage() + " trying to download " + url);
return null;
}
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
public static Observable<BaseDanmakuParser> downloadXML(final String uri) {
return Observable.create((Observable.OnSubscribe<BaseDanmakuParser>) subscriber -> {
if (TextUtils.isEmpty(uri)) {
subscriber.onNext(new BaseDanmakuParser() {
@Override
protected IDanmakus parse() {
return new Danmakus();
}
});
}
ILoader loader = null;
try {
HttpConnection.Response rsp = (HttpConnection.Response)
Jsoup.connect(uri).timeout(20000).execute();
InputStream stream = new ByteArrayInputStream(BiliDanmukuCompressionTools.
decompressXML(rsp.bodyAsBytes()));
loader = DanmakuLoaderFactory.
create(DanmakuLoaderFactory.TAG_BILI);
loader.load(stream);
} catch (IOException | DataFormatException | IllegalDataException e) {
e.printStackTrace();
}
BaseDanmakuParser parser = new BiliDanmukuParser();
assert loader != null;
IDataSource<?> dataSource = loader.getDataSource();
parser.load(dataSource);
subscriber.onNext(parser);
}).subscribeOn(Schedulers.io());
}
}
代码示例来源:origin: RipMeApp/ripme
logger.debug("Retrieving " + UpdateUtils.updateJsonURL);
doc = Jsoup.connect(UpdateUtils.updateJsonURL)
.timeout(10 * 1000)
.ignoreContentType(true)
.get();
代码示例来源:origin: RipMeApp/ripme
private static Document getDocument(String strUrl) throws IOException {
return Jsoup.connect(strUrl)
.userAgent(USER_AGENT)
.timeout(10 * 1000)
.maxBodySize(0)
.get();
}
代码示例来源:origin: RipMeApp/ripme
logger.debug("Retrieving " + UpdateUtils.updateJsonURL);
doc = Jsoup.connect(UpdateUtils.updateJsonURL)
.timeout(10 * 1000)
.ignoreContentType(true)
.get();
代码示例来源:origin: ChinaSilence/any-video
public static Document getDocWithPhone(String url) {
try {
return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).ignoreContentType(true).validateTLSCertificates(false).get();
} catch (IOException e) {
log.error(ERROR_DESC + url);
throw new AnyException(ERROR_DESC + url);
}
}
代码示例来源:origin: ChinaSilence/any-video
public static Document getDocWithPhone(String url, String cookie) {
try {
return Jsoup.connect(url).userAgent(UA_PHONE).timeout(TIME_OUT).header("Cookie", cookie).ignoreContentType(true).get();
} catch (IOException e) {
log.error(ERROR_DESC + url);
throw new AnyException(ERROR_DESC + url);
}
}
代码示例来源:origin: RipMeApp/ripme
private void defaultSettings() {
this.retries = Utils.getConfigInteger("download.retries", 1);
connection = Jsoup.connect(this.url);
connection.userAgent(AbstractRipper.USER_AGENT);
connection.method(Method.GET);
connection.timeout(TIMEOUT);
connection.maxBodySize(0);
}
代码示例来源:origin: magefree/mage
public static Document downloadHtmlDocument(String urlString) throws NumberFormatException, IOException {
Preferences prefs = MageFrame.getPreferences();
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
Document doc;
if (proxyType == ProxyType.NONE) {
doc = Jsoup.connect(urlString).timeout(60 * 1000).get();
} else {
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
URL url = new URL(urlString);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
uc.setConnectTimeout(10000);
uc.setReadTimeout(60000);
uc.connect();
String line;
StringBuffer tmp = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ((line = in.readLine()) != null) {
tmp.append(line);
}
doc = Jsoup.parse(String.valueOf(tmp));
}
return doc;
}
}
代码示例来源:origin: pengwei1024/AndroidSourceViewer
@NotNull
@Override
public Set<SearchEntity> search(@NotNull String keyword) {
Set<SearchEntity> result = new HashSet<>();
try {
Document doc = Jsoup.connect(SEARCH_URL + keyword).timeout(3000).get();
Elements searchItems = doc.getElementsByClass("g");
if (!searchItems.isEmpty()) {
for (Element element : searchItems) {
Elements nodeA = element.getElementsByTag("a");
System.out.println(nodeA.first());
}
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
代码示例来源:origin: YuanKJ-/JsCrawler
@Override
protected void processTimeout(RequestModel model) {
if(model.getTimeout() != null) {
connection.timeout(model.getTimeout());
}
}
代码示例来源:origin: malmstein/yahnac
private static Connection defaultConnection(String baseUrlExtension) {
Connection conn = Jsoup.connect(BASE_URL + baseUrlExtension)
.timeout(TIMEOUT_MILLIS)
.userAgent(USER_AGENT);
conn.header("Accept-Encoding", "gzip");
return conn;
}
代码示例来源:origin: avluis/Hentoid
@Nullable
public Content parseContent(String urlString) throws IOException {
Document doc = Jsoup.connect(urlString).timeout(TIMEOUT).get();
Content content = parseContent(doc);
if (content != null) {
content.populateAuthor();
content.setStatus(StatusContent.SAVED);
}
return content;
}
代码示例来源:origin: LABELNET/YuanNews
public static void testHuanQiuIndexPage() throws IOException {
Document doc = Jsoup.connect(HuanQiuUrl).timeout(100000).get();
Set<String> qiuUrls = ParseIndex.getHuanQiuUrls(doc);
LoggerUtil.printJSON(qiuUrls);
}
代码示例来源:origin: BeelGroup/Docear-Desktop
protected Connection getConnection(String URL) {
return Jsoup.connect(URL)
.ignoreContentType(true)
.userAgent(this.userAgent)
.referrer(this.referrer)
.timeout(this.timeout)
.followRedirects(this.followRedirects);
}
内容来源于网络,如有侵权,请联系作者删除!