本文整理汇总了Java中org.jsoup.Connection.cookie方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.cookie方法的具体用法?Java Connection.cookie怎么用?Java Connection.cookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.Connection
的用法示例。
在下文中一共展示了Connection.cookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<Winner> doInBackground(Void... params) {
Log.d(TAG, "Fetching giveaways for page " + page);
try {
// Fetch the Giveaway page
Connection jsoup = Jsoup.connect("https://www.steamgifts.com/giveaway/" + path + "/winners/search")
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
jsoup.data("page", Integer.toString(page));
if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
Document document = jsoup.get();
SteamGiftsUserData.extract(fragment.getContext(), document);
return loadAll(document);
} catch (IOException e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例5: 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;
}
}
示例6: getConnection
import org.jsoup.Connection; //导入方法依赖的package包/类
/**
* Get an object connection with referer and cookie setted
* @param url url to get
* @param cookies cookies for the new connection
* @param referer
* @return a connection
*/
public static Connection getConnection(String url, Map<String, String> cookies, String referer) {
Connection result = null;
result = Jsoup.connect(url).method(Method.GET).header("Host", CommonConst.HOST_KRALAND);
if (referer != null) {
result.referrer(referer);
}
if (cookies != null) {
for (Map.Entry<String, String> entry : cookies.entrySet()) {
result.cookie(entry.getKey(), entry.getValue());
}
}
return result;
}
示例7: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<IEndlessAdaptable> doInBackground(Void... params) {
try {
// Fetch the Giveaway page
Connection jsoup = Jsoup.connect("https://www.steamgifts.com/" + pathSegment + "/search")
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
jsoup.data("page", Integer.toString(page));
if (searchQuery != null)
jsoup.data("q", searchQuery);
jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(context).getSessionId());
Document document = jsoup.get();
SteamGiftsUserData.extract(context, document);
// Fetch the xsrf token
Element xsrfToken = document.select("input[name=xsrf_token]").first();
if (xsrfToken != null)
foundXsrfToken = xsrfToken.attr("value");
// Do away with pinned giveaways.
document.select(".pinned-giveaways__outer-wrap").html("");
// Parse all rows of giveaways
return loadAll(document);
} catch (Exception e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例8: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<Giveaway> doInBackground(Void... params) {
Log.d(TAG, "Fetching giveaways for user " + path + " on page " + page);
try {
// Fetch the Giveaway page
Connection connection = Jsoup.connect("https://www.steamgifts.com/user/" + path + "/search")
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
connection.data("page", Integer.toString(page));
if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn()) {
connection.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
connection.followRedirects(false);
}
Connection.Response response = connection.execute();
Document document = response.parse();
if (response.statusCode() == 200) {
SteamGiftsUserData.extract(fragment.getContext(), document);
if (!user.isLoaded())
foundXsrfToken = Utils.loadUserProfile(user, document);
// Parse all rows of giveaways
return Utils.loadGiveawaysFromList(document);
} else {
Log.w(TAG, "Got status code " + response.statusCode());
return null;
}
} catch (Exception e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例9: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<IEndlessAdaptable> doInBackground(Void... params) {
try {
// Fetch the messages page
Connection jsoup = Jsoup.connect("https://www.steamgifts.com/messages/search")
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
jsoup.data("page", Integer.toString(page));
jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(context).getSessionId());
Document document = jsoup.get();
SteamGiftsUserData.extract(context, document);
// Fetch the xsrf token
Element xsrfToken = document.select("input[name=xsrf_token]").first();
if (xsrfToken != null)
foundXsrfToken = xsrfToken.attr("value");
// Parse all rows of giveaways
return loadMessages(document);
} catch (Exception e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例10: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<BasicUser> doInBackground(Void... params) {
try {
// Fetch the Giveaway page
String url = "https://www.steamgifts.com/account/manage/" + what.name().toLowerCase(Locale.ENGLISH) + "/search";
Log.d(TAG, "Fetching URL " + url);
Connection jsoup = Jsoup.connect(url)
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT)
.followRedirects(false);
jsoup.data("page", Integer.toString(page));
if (searchQuery != null)
jsoup.data("q", searchQuery);
jsoup.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();
if (xsrfToken != null)
foundXsrfToken = xsrfToken.attr("value");
// Do away with pinned giveaways.
document.select(".pinned-giveaways__outer-wrap").html("");
// Parse all rows of giveaways
return loadAll(document);
} catch (Exception e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例11: connect
import org.jsoup.Connection; //导入方法依赖的package包/类
private Connection.Response connect() throws IOException {
String url = "https://www.steamgifts.com/discussion/" + discussionId + "/search?page=" + page;
Log.v(TAG, "Fetching discussion details for " + url);
Connection connection = Jsoup.connect(url)
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT)
.followRedirects(true);
if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
connection.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
return connection.execute();
}
示例12: cookie
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void cookie() {
Connection con = HttpConnection.connect("http://example.com/");
con.cookie("Name", "Val");
assertEquals("Val", con.request().cookie("Name"));
}
示例13: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<Giveaway> doInBackground(Void... params) {
Log.d(TAG, "Fetching giveaways for page " + page);
try {
// Fetch the Giveaway page
Connection jsoup = Jsoup.connect("https://www.steamgifts.com/giveaways/search")
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
jsoup.data("page", Integer.toString(page));
if (searchQuery != null)
jsoup.data("q", searchQuery);
FilterData filterData = FilterData.getCurrent(fragment.getContext());
if (!filterData.isEntriesPerCopy()) {
addFilterParameter(jsoup, "entry_max", filterData.getMaxEntries());
addFilterParameter(jsoup, "entry_min", filterData.getMinEntries());
}
if (!filterData.isRestrictLevelOnlyOnPublicGiveaways()) {
addFilterParameter(jsoup, "level_min", filterData.getMinLevel());
addFilterParameter(jsoup, "level_max", filterData.getMaxLevel());
}
addFilterParameter(jsoup, "region_restricted", filterData.isRegionRestrictedOnly());
addFilterParameter(jsoup, "copy_min", filterData.getMinCopies());
addFilterParameter(jsoup, "copy_max", filterData.getMaxCopies());
addFilterParameter(jsoup, "point_min", filterData.getMinPoints());
addFilterParameter(jsoup, "point_max", filterData.getMaxPoints());
if (type != GiveawayListFragment.Type.ALL)
jsoup.data("type", type.name().toLowerCase(Locale.ENGLISH));
if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
jsoup.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();
if (xsrfToken != null)
foundXsrfToken = xsrfToken.attr("value");
// Do away with pinned giveaways.
if (!showPinnedGiveaways)
document.select(".pinned-giveaways__outer-wrap").html("");
// Parse all rows of giveaways
return Utils.loadGiveawaysFromList(document);
} catch (Exception e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例14: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<Discussion> doInBackground(Void... params) {
try {
// Fetch the Giveaway page
String segment = "";
if (type != DiscussionListFragment.Type.ALL)
segment = type.name().replace("_", "-").toLowerCase(Locale.ENGLISH) + "/";
String url = "https://www.steamgifts.com/discussions/" + segment + "search";
Log.d(TAG, "Fetching discussions for page " + page + " and URL " + url);
Connection jsoup = Jsoup.connect(url)
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
jsoup.data("page", Integer.toString(page));
if (searchQuery != null)
jsoup.data("q", searchQuery);
// We do not want to follow redirects here, because SteamGifts redirects to the main (giveaways) page if we're not logged in.
// For all other pages however, if we're not logged in, we're redirected once as well?
if (type == DiscussionListFragment.Type.CREATED)
jsoup.followRedirects(false);
if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
Document document = jsoup.get();
SteamGiftsUserData.extract(fragment.getContext(), document);
// Parse all rows of discussions
Elements discussions = document.select(".table__row-inner-wrap");
Log.d(TAG, "Found inner " + discussions.size() + " elements");
List<Discussion> discussionList = new ArrayList<>();
for (Element element : discussions) {
Element link = element.select("h3 a").first();
// Basic information
Uri uri = Uri.parse(link.attr("href"));
String discussionId = uri.getPathSegments().get(1);
String discussionName = uri.getPathSegments().get(2);
Discussion discussion = new Discussion(discussionId);
discussion.setTitle(link.text());
discussion.setName(discussionName);
Element p = element.select(".table__column--width-fill p").first();
discussion.setCreatedTime(Integer.valueOf(p.select("span").first().attr("data-timestamp")));
discussion.setCreator(p.select("a").last().text());
// The creator's avatar
Element avatarNode = element.select(".table_image_avatar").first();
if (avatarNode != null)
discussion.setCreatorAvatar(Utils.extractAvatar(avatarNode.attr("style")));
discussion.setLocked(element.hasClass("is-faded"));
discussion.setPoll(!element.select("h3 i.fa-align-left").isEmpty());
discussionList.add(discussion);
}
return discussionList;
} catch (Exception e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}
示例15: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected List<GiveawayGroup> doInBackground(Void... params) {
Log.d(TAG, "Fetching giveaways for page " + page);
try {
// Fetch the Giveaway page
Connection jsoup = Jsoup.connect("https://www.steamgifts.com/giveaway/" + path + "/groups/search")
.userAgent(Constants.JSOUP_USER_AGENT)
.timeout(Constants.JSOUP_TIMEOUT);
jsoup.data("page", Integer.toString(page));
if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
Document document = jsoup.get();
SteamGiftsUserData.extract(fragment.getContext(), document);
// Parse all rows of groups
Elements groups = document.select(".table__row-inner-wrap");
Log.d(TAG, "Found inner " + groups.size() + " elements");
List<GiveawayGroup> groupList = new ArrayList<>();
for (Element element : groups) {
Element link = element.select(".table__column__heading").first();
// Basic information
String title = link.text();
String id = link.attr("href").substring(7, 12);
String avatar = null;
Element avatarNode = element.select(".global__image-inner-wrap").first();
if (avatarNode != null)
avatar = Utils.extractAvatar(avatarNode.attr("style"));
GiveawayGroup group = new GiveawayGroup(id, title, avatar);
groupList.add(group);
}
return groupList;
} catch (IOException e) {
Log.e(TAG, "Error fetching URL", e);
return null;
}
}