Skip to content

Questions about JavaScript dynamic pages #74

Description

@hahafather007

The information I get on the page is always the source code, I can't get the rendered page code.
How can I get the page after the dynamic rendering is complete, just like checking it in Chrome?
And my code like this:

fun main(args: Array<String>) {
    val client = WebClient(BrowserVersion.CHROME).apply {
        options.apply {
            isCssEnabled = true
            isJavaScriptEnabled = true
            isThrowExceptionOnScriptError = false
            isRedirectEnabled = true
            isActiveXNative = true
        }
        javaScriptEngine = CustomJsEngine(this)
        ajaxController = NicelyResynchronizingAjaxController()
        waitForBackgroundJavaScript(10 * 1000)
    }
    Damai.start(client)
    client.close()
}
object Damai {
    /**
     * 打开买票界面
     * @param client 浏览器实例
     */
    fun start(client: WebClient) {
        val scanner = Scanner(System.`in`)
//        val url = scanner.next()
        val url = "https://detail.damai.cn/item.htm?spm=a2oeg.home.card_0.ditem_1.591b23e1KA3wRj&id=601539289783"
        println("大麦网购票地址:")
        val homePage = client.getPage<HtmlPage>(url)
//        println(homePage.asText())
        val loginBtn = homePage.getFirstByXPath<HtmlSpan>(
                "//div[@class='dm-header-wrap']//div[@class='dm-header-box']//div[@class='right-header']" +
                        "//div[@class='box-header user-header']//div[@class='login-user show']" +
                        "//span[@class='span-box-header span-user']")
        startLogin(loginBtn.click())
    }

    /**
     * 进行登陆
     * @param page 点击后的登陆界面
     */
    private fun startLogin(page: HtmlPage) {
        val loginDiv = page.getHtmlElementById<HtmlDivision>("alibaba-login-iframe")
        println(loginDiv.asXml())
    }
}

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions