没有从使用jsoup的网站获取所有html

时间:2017-02-02 23:14:30

标签: java html web jsoup

我知道有很多这类问题,但我没有找到答案......

所以问题与主题一样。在开始网页要求我输入登录名和密码 - 登录后我试图获得整个HTML但不是我有10-20%的html和其余的接收数据甚至不知道从哪里(例子下文)...

> <script type="text/javascript">
> 
> window.currentUserName="******"; 
> window.currentUserGroups={};
> window.currentUserRoles={};
> 
> window.currentUserGroups['InventoryEditor']=true;
> window.currentUserRoles['InventoryEditor']=true;
> window.currentUserGroups['inventoryScriptBypass']=true;
> window.currentUserRoles['User']=true;
> window.currentUserGroups['rsuser']=true;
> window.currentUserRoles['User']=true;
> 
> 
> window.getCurrentUserName = function() {
>     return window.currentUserName; };
> 
> window.currentUserHasGroup = function(groupName) {
>     return window.currentUserGroups[groupName] ? true : false; };
> 
> window.currentUserHasGroups = function(groupNames) {
>     for (var i = 0; i < groupNames.length; i++) {
>         if (window.currentUserHasGroup(groupNames[i])) {
>             return true;
>         }
>     }
>     return false; };

还有更多......

我的源代码如下:

Connection.Response loginForm = Jsoup.connect("Website before login")
        .method(Connection.Method.GET)
        .execute();

Document document = Jsoup.connect("Website after login")
        //.maxBodySize(0)
        //.timeout(0)
        .data("cookieexists", "false")
        .data("login", "login")
        .data("password", "password")
        .data("submit", "Sign in")
        .cookies(loginForm.cookies())
        .get();

的System.out.println(文件); }

当我在登录前尝试从网站获取HTML时,它运行良好... 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

“如果内容依赖于javascript,那么jsoup是不够的(没有javascript支持)。如果你使用了搜索,你应该阅读推荐使用例如HtmlUnit。没有页面URL和登录凭据,问题是不可复制。“