尝试从网站检索数据时出错?

时间:2015-08-18 16:36:31

标签: java html web

public int getVotes()
{
    int value = -1;

    try
    {
        URL url = new URL(Config.TOPZONE_SERVER_LINK);
        URLConnection con = url.openConnection();
        con.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
        InputStreamReader isr = new InputStreamReader(con.getInputStream());
        BufferedReader in = new BufferedReader(isr);
        String inputLine;
        String dataline = "TEST STRING";
        Map<Integer, String> webInfo = new HashMap<>();
        int i = 0;

        while ((inputLine = in.readLine()) != null)
        {
            webInfo.put(i, inputLine);
            if (inputLine.contains("<i class=\"fa fa-fw fa-lg fa-thumbs-up\"></i>"))
            {
                dataline = inputLine;
                value = Integer.valueOf(inputLine.split("<i class=\"fa fa-fw fa-lg fa-thumbs-up\"></i>")[1].replace("</span></small></h3>", "").trim());
            }
            i++;
        }

        isr.close();
        in.close();

        if (value != -1)
        {
            File file = new File("./log/TopZoneNice.txt");

            if (!file.exists())
                file.createNewFile();

            Date currentDate = new Date(System.currentTimeMillis());
            DateFormat df = new SimpleDateFormat("dd:MM:yy HH:mm:ss");

            FileWriter fileWriter = new FileWriter(file.getAbsoluteFile(), true);
            BufferedWriter bufWriter = new BufferedWriter(fileWriter);

            bufWriter.append(df.format(currentDate) + " VOTES: " + value + " *[ " + dataline.trim() + " ]");
            bufWriter.newLine();

            bufWriter.close();
        }
        if (value == -1)
        {
            File file = new File("./log/TopZoneWrong.txt");

            if (!file.exists())
                file.createNewFile();

            Date currentDate = new Date(System.currentTimeMillis());
            DateFormat df = new SimpleDateFormat("dd:MM:yy HH:mm:ss");

            FileWriter fileWriter = new FileWriter(file.getAbsoluteFile(), true);
            BufferedWriter bufWriter = new BufferedWriter(fileWriter);

            bufWriter.append(df.format(currentDate) + " VOTES: " + value + " *[ " + dataline.trim() + " ]");
            bufWriter.newLine();

            bufWriter.close();

            File file1 = new File("./log/TopZoneSite.txt");

            if (!file1.exists())
                file1.createNewFile();

            FileWriter fileWriter1 = new FileWriter(file1.getAbsoluteFile());
            BufferedWriter bufWriter1 = new BufferedWriter(fileWriter1);
            for (int y = 0; y < webInfo.size(); y++)
            {
                bufWriter1.append(webInfo.get(y));
                bufWriter1.newLine();
            }

            bufWriter1.close();
        }
    }
    catch (IOException e)
    {
        _log.warning("L2Topzone Vote system is offline.");
        _log.warning("AutoVoteRewardHandler: " + e);
    }
    return value;
}

我使用此代码从此http://l2topzone.com/lineage/server-info/12487/l2exhale

中检索我想要的数据

但是我不时得到-1作为结果。 记录器给了我这个

<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="/hf-system/hf-lib.php"></script>
<script type="text/javascript" src="/hf-system/hf-help.php"></script>
<script type="text/javascript">
var a=toNumbers("d236bc5a72df6a6cf3d4ad6f684bf34d"),b=toNumbers("63c25144e3ee3b8954f826a111307cea"),c=toNumbers("88d899690df58c8444b9de5d601b8dcf");
createCookie("___HFUID",toHex(slowAES.decrypt(c,2,a,b)),7);
createCookie("___HFDOM",getCookieDomain());
location.replace("http://l2topzone.com/lineage/server-info/12487/l2exhale");
</script>
</head>
<body>
<noscript><center>
This website requires javascript/cookies support in order to operate properly.
</center></noscript>
</body>
</html>

有关如何解决此问题的任何想法?

0 个答案:

没有答案