(翻译) 我使用这段代码:
println("load cookies...")
val cookies: Set<DecryptedCookie> = ChromeBrowser().cookies as Set<DecryptedCookie>
println("load client...")
val browser = HtmlUnitDriver(true)
println("transfer cookies...")
for(cookie in cookies)
{
println(cookie.domain)
browser.manage().cookies.add(Cookie(cookie.name, cookie.decryptedValue, cookie.domain, cookie.path, cookie.expires))
}
println("load url...")
browser.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS)
browser.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS)
browser.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS)
browser.get("http://www.cyberforum.ru")
println(browser.pageSource)
但是打开链接没有登录。使用chrome导入cookie就像成功...
答案 0 :(得分:0)
我决定了。有必要通过Manage中的方法添加。也只能使用url并刷新^
val domain = "www.cyberforum.ru"
val site = "http://www.cyberforum.ru/"
val cookies = ChromeBrowser().getCookiesForDomain(domain) as Set<DecryptedCookie>
val browser = HtmlUnitDriver(true)
browser.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS)
browser.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS)
browser.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS)
browser.get(site)
for(cookie in cookies)
browser.manage().addCookie(Cookie(cookie.name, cookie.decryptedValue, cookie.path, cookie.expires))
browser.get(site)
println(browser.pageSource)