通过验证和执行表单来刮页

时间:2019-05-28 16:52:02

标签: java web-scraping okhttp

我已从开发人员工具中从浏览器中提取了cURL,并将其导入Postman中,以通过Unirest或OkHttp作为代码提取。我的意图是自动对网站进行身份验证,从HTML转到特定页面并解析HTML中显示的一些数字。目前,这种情况是手动发生的,并试图避免这种情况。

我可以从Postman进行身份验证,但是当我执行通过服务提取的代码时,我无法获得有效的响应,并且似乎也无法从一页转移到另一页。

我的Java最独特之处如下;

        HttpResponse<String> response = Unirest.post("url")
            .header("connection", "keep-alive")
            .header("cache-control", "no-cache")
            .header("origin", "url")
            .header("upgrade-insecure-requests", "1")
            .header("content-type", "application/x-www-form-urlencoded")
            .header("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/11.1.1111.11 Safari/537.36")
            .header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
            .header("referer", "url")
            .header("accept-encoding", "gzip, deflate, br")
            .header("accept-language", "en-GB,en-US;q=0.9,en;q=0.8")
            .header("cookie", "87t0hUB9Dy0ukQaSIeFJRE2Emc2refkuTG47EVGRqzGRjnRTTKAteaGQ==; JSESSIONID=U+tpAeNb93ye-mNGJMtaOC8v")
            .header("postman-token", "f51f2b6e-e847-0195-47b9-45911bb92fde")
            .body("forward=&login=username&password=password")
            .asString();

如何自动登录JSP表单,从同一客户端移至页面并通过自动按下按钮来执行另一种表单?

0 个答案:

没有答案