本文整理汇总了Java中org.jsoup.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于org.jsoup包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
});
}
}
示例3: getUserInfo
import org.jsoup.Connection; //导入依赖的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;
}
示例4: rip
import org.jsoup.Connection; //导入依赖的package包/类
@Override
public void rip() throws IOException {
String gid = getGID(this.url);
String theurl = "http://newsfilter.org/gallery/" + gid;
logger.info("Loading " + theurl);
Connection.Response resp = Jsoup.connect(theurl)
.timeout(5000)
.referrer("")
.userAgent(USER_AGENT)
.method(Connection.Method.GET)
.execute();
Document doc = resp.parse();
Elements thumbnails = doc.select("#galleryImages .inner-block img");
for (Element thumb : thumbnails) {
String thumbUrl = thumb.attr("src");
String picUrl = thumbUrl.replace("thumbs/", "");
addURLToDownload(new URL(picUrl));
}
waitForThreads();
}
示例5: login
import org.jsoup.Connection; //导入依赖的package包/类
private synchronized boolean login() throws IOException {
log.info("Authenticating to GS admin panel");
String username = getUsername();
String password = getPassword();
rateLimiter.acquire(2);
Connection.Response loginForm = Jsoup.connect(LOGIN_URL)
.method(Connection.Method.GET)
.userAgent(USER_AGENT)
.execute();
if (loginForm.statusCode() == 403) {
log.warn("Disabling panel due to 403");
enabled = false;
}
rateLimiter.acquire(2);
Document document = Jsoup.connect(LOGIN_URL)
.userAgent(USER_AGENT)
.data("logout", "1")
.data("username", username)
.data("password", password)
.data("query_string", "")
.cookies(loginForm.cookies())
.post();
session.clear();
session.putAll(loginForm.cookies());
return !isLoginPage(document);
}
示例6: doInBackground
import org.jsoup.Connection; //导入依赖的package包/类
@Override
@Deprecated
protected List<Elements> doInBackground(String... params) {
List<Elements> results = new ArrayList<>();
int idx = 0;
try {
Connection.Response response = Jsoup.connect(url())
.data(data())
.method(method())
.cookies(cookies())
.execute();
cookies = response.cookies();
for (String param : params) {
if (!TextUtils.isEmpty(param)) {
results.add(response.parse().select(param));
}
publishProgress((int) ((double) (++idx / params.length)) * 100);
}
} catch (IOException e) {
e.printStackTrace();
}
return results;
}
示例7: getWebPreviewFromURL
import org.jsoup.Connection; //导入依赖的package包/类
public static Web getWebPreviewFromURL(String url) throws IllegalArgumentException, IOException {
Connection.Response response = null;
Web web = null;
response = Jsoup.connect(url)
.userAgent("Mozilla/5.0")
.ignoreHttpErrors(true)
.execute();
if (response.statusCode() != 200) {
return null;
}
web = parseWeb(response);
return web;
}
示例8: unlockParental
import org.jsoup.Connection; //导入依赖的package包/类
/**
* Unlock Steam parental controls with a pin
*/
private String unlockParental(String pin) {
final String url = STEAM_STORE + "parental/ajaxunlock";
try {
final Map<String,String> responseCookies = Jsoup.connect(url)
.referrer(STEAM_STORE)
.followRedirects(true)
.ignoreContentType(true)
.cookies(generateWebCookies())
.data("pin", pin)
.method(Connection.Method.POST)
.execute()
.cookies();
return responseCookies.get("steamparental");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例9: postPageByUrl
import org.jsoup.Connection; //导入依赖的package包/类
public Document postPageByUrl(String url, String[][] params) throws IOException {
Connection connection = Jsoup.connect(url);
for (String[] data : params) {
connection.data(data[0], data[1]);
}
Connection.Response response = connection.cookies(getCookies())
.followRedirects(true)
.method(Connection.Method.POST)
.execute();
this.cookies.addItems(response.cookies());
return response.parse();
}
示例10: getLoginResponse
import org.jsoup.Connection; //导入依赖的package包/类
/**
* 登录接口获取响应
*
* @param user
* @return
*/
public static Response getLoginResponse(User user) {
Map<String, String> map = new HashMap<>();
map.put(Constant.Login.PARAM_USERNAME, user.getUsername());
map.put(Constant.Login.PARAM_PASSWORD, user.getPassword());
try {
return Jsoup.connect(Constant.Login.LOGIN_URL)
.data(map)
.ignoreContentType(true)
.method(Connection.Method.POST)
.timeout(10000)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例11: getSchoolNotice
import org.jsoup.Connection; //导入依赖的package包/类
/**
* 获取学校通知接口
*
* @param cookiesMap
* @param index
* @return
*/
public static Response getSchoolNotice(Map<String, String> cookiesMap, int index) {
try {
Connection con = Jsoup.connect(Constant.SchoolNotice.URL);
con.ignoreContentType(true);
Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> en = it.next();
con = con.cookie(en.getKey(), en.getValue());
}
return con.method(Connection.Method.POST)
.data(Constant.SchoolNotice.PARAM_PAGE_SIZE, "10")
.data(Constant.SchoolNotice.PARAM_PAGE_INDEX, String.valueOf(index))
.data(Constant.SchoolNotice.PARAM_A_TITLE, "")
.data(Constant.SchoolNotice.PARAM_ORDER_BY_TYPE, "asc")
.timeout(10000)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例12: getCourseId
import org.jsoup.Connection; //导入依赖的package包/类
/**
* 获取课程id
*
* @param cookiesMap
* @return
*/
public static Response getCourseId(Map<String, String> cookiesMap) {
try {
Connection con = Jsoup.connect(Constant.CoursePraise.COURSE_URL);
con.ignoreContentType(true);
Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> en = it.next();
con = con.cookie(en.getKey(), en.getValue());
}
return con.method(Connection.Method.GET)
.data(Constant.CoursePraise.COURSE_URL_OTHER_PARAM, "zTreeAsyncTest")
.data(Constant.CoursePraise.COURSE_URL_, "1507812989512")
.timeout(10000)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例13: getCourseInfo
import org.jsoup.Connection; //导入依赖的package包/类
public static Response getCourseInfo(Map<String, String> cookiesMap, String id, String name) {
try {
Connection con = Jsoup.connect(Constant.CoursePraise.COURSE_URL);
con.ignoreContentType(true);
Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> en = it.next();
con = con.cookie(en.getKey(), en.getValue());
}
return con.method(Connection.Method.GET)
.data("id", id)
.data("name", name)
.data("pId", "")
.data("level", "0")
.data(Constant.CoursePraise.COURSE_URL_OTHER_PARAM, "zTreeAsyncTest")
.data(Constant.CoursePraise.COURSE_URL_, "1507812989512")
.timeout(10000)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例14: onPostExecute
import org.jsoup.Connection; //导入依赖的package包/类
@Override
protected void onPostExecute(Connection.Response response) {
super.onPostExecute(response);
if (response != null) {
String body = response.body();
if (body != null) {
// TODO 获取成功,保存到本地
LogUtils.d(body);
Type listType = new TypeToken<List<Course.CourseInfo>>() {
}.getType();
courseInfoList = gson.fromJson(body, listType);
// TODO 根据CourseId查询课程信息
if (!courseInfoList.isEmpty()) {
for (int i = 0; i < courseInfoList.size(); i++) {
new CoursePraiseInfoAsyncTask(context, onLoadCallback).execute(courseInfoList.get(i));
}
} else {
onLoadCallback.onFailed(Constant.Connect.ERROR);
}
} else {
onLoadCallback.onFailed(Constant.Connect.ERROR);
}
} else {
onLoadCallback.onFailed(Constant.Network.Network_ERROR);
}
}
示例15: GetTotalPages
import org.jsoup.Connection; //导入依赖的package包/类
/**
* 获取总页数,返回给前台
* 参数
*
* @param cityCode 城市
* @param minPrice 最低价格
* @param maxPrice 最高价格
* @return
*/
@ResponseBody
@RequestMapping(value = "/GetTotalPages", method = RequestMethod.POST)
public int GetTotalPages(String cityCode, int minPrice, int maxPrice, String area, String subway) {
//构建URL
String oldUrl = "http://" + cityCode + ".58.com";
Connection conn = Jsoup.connect(oldUrl);
int pages = 0;
try {
Response response = conn.method(Method.GET).execute();
newUrl = response.url().toString() + "/pinpaigongyu/pn/";
String nowUrl = newUrl + "1/?minprice=" + minPrice + "_" + maxPrice + area + subway;
Document doc = Jsoup.connect(nowUrl).get();
int listsum = Integer.valueOf(doc.getElementsByClass("listsum").select("em").text());
pages = listsum % 20 == 0 ? listsum / 20 : listsum / 20 + 1; //计算页数
} catch (IOException ex) {
}
return pages;
}