JSoup似乎正在跳过HTML字符串中的某些元素。 我100%肯定HTML字符串中的所有内容,但是JSoup仅在选择要解析的元素时才读取其中的某些元素,或者根本不读取任何元素。 但我知道它们存在。 这是我的代码:谢谢:

public void parseDoc() {
    final HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, true);
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
            "https://secure.groupfusion.net/processlogin.php");
    String HTML = "";
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("referral_page",
                "/modules/gradebook/ui/gradebook.phtml?type=student_view"));
        nameValuePairs.add(new BasicNameValuePair("currDomain",
                "beardenhs.knoxschools.org"));
        nameValuePairs.add(new BasicNameValuePair("username", username
                .getText().toString()));
        nameValuePairs.add(new BasicNameValuePair("password", password
                .getText().toString()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

        HTML = EntityUtils.toString(response.getEntity());
        Document doc = Jsoup.parse(HTML);
        Element link = doc.select("a").first();
        String linkHref = link.attr("href");
        HttpGet request = new HttpGet();
        try {
            request.setURI(new URI(linkHref));
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response = httpclient.execute(request);
        String html = "";
        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            str.append(line);
        }
        in.close();
        HTML = str.toString();
        doc = Jsoup.parse(HTML);
        Elements divs = doc.select("div.yuiTop");
        for (Element d: divs) {
            sting.append(d.text());
            sting.append("\n");
        }


    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

}

===============>>#1 票数:1 已采纳

这里有种奇怪的代码...所以我收集到这是在进行查询,结果将返回超链接列表,并且您正在对第一个超链接的结果进行屏幕抓取,然后尝试加载内容第二个链接? 好吧,您确定服务器正在返回有效的超链接吗? 尝试在浏览器中加载页面。

如果有效,那么我不确定是什么问题,但是为什么不使用WebView.loadUrl()并让浏览器组件来处理呢?

  ask by Eli translate from so

未解决问题?本站智能推荐: