我需要加载页面并发送输入字段请求(ajax)。我使用这段代码:
val cookies = ChromeBrowser().getCookiesForDomain(domain) as Set<DecryptedCookie>
val browser = object : HtmlUnitDriver(true)
{
override fun modifyWebClient(client: WebClient): WebClient
{
client.options.isThrowExceptionOnFailingStatusCode = false
client.options.isThrowExceptionOnScriptError = false
return client
}
}
browser.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS)
browser.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS)
browser.manage().timeouts().setScriptTimeout(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)
browser.findElementById("id-search").sendKeys("3582181")
browser.findElementById("id-search-refresh").click()
waitController.withTimeout(Duration.ofSeconds(10))
println(browser.pageSource)
Ajax conent不在页面源上。求助。