网站没有使用JSoup获取所有POST数据

时间:2015-07-24 15:54:51

标签: java html jsoup

我正在尝试登录网站并尝试映射数据以查看英语到法语的翻译是否正确,但出于某种原因,它所采用的唯一数据是用户名和密码,并忽略所有与语言相关的数据。

这就是我的尝试:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import sun.audio.*;
import java.io.*;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.MouseEvent;

public class playFishGame extends JPanel implements MouseMotionListener {
   private JFrame board;// the main board
   private JLabel fish;
   private JLabel enemyFishS;
   private JLabel enemyFishS2;
   private JLabel enemyFishS3;
   private ImageIcon fishPic;
   private ImageIcon enemyFishSPic;
   private ImageIcon winBackground;
   private ImageIcon background;
   private ImageIcon loseBackground;
   ImageIcon fishSmall1r = new ImageIcon("data/fishSmall1r.png");
   ImageIcon fishSmall1l = new ImageIcon("data/fishSmall1l.png");
   ImageIcon fishSmall2r = new ImageIcon("data/fishSmall2r.png");
   ImageIcon fishSmall2l = new ImageIcon("data/fishSmall2l.png");
   ImageIcon fishSmall4r = new ImageIcon("data/fishSmall4r.png");
   ImageIcon fishSmall4l = new ImageIcon("data/fishSmall4l.png");
   private fish fishFish;
   private fish enemyFishSFish;
   private fish enemyFishSFish2;
   private fish enemyFishSFish3;
   private int origin;
   private boolean contact, win;
   Cursor blankCursor = null;

   public static void main(String args[]) {
      playFishGame play = new playFishGame();
   }

   public playFishGame() {
      blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
            Toolkit.getDefaultToolkit().createImage("data/blank.png"),
            new Point(0, 0), "blankCursor"); // blank.png is any tranparent
                                             // image.
      board = new JFrame("Play Fish Game");
      board.setSize(1300, 700);
      board.getContentPane().setCursor(blankCursor);
      board.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      board.add(this);// adds JLabel to JFrame
      this.addMouseMotionListener(this);
      board.setVisible(true);
      ImageIcon fishPic = new ImageIcon("data/sfr.gif");
      fish = new JLabel(fishPic);
      enemyFishS = new JLabel(" ");
      enemyFishS2 = new JLabel(" ");
      fishFish = new fish(617, 0);
      enemyFishSFish = new fish(1300, 350);
      enemyFishSFish2 = new fish(0, 500);
      // enemyFishSFish3= new fish(1300,200);
      this.add(fish);
      this.add(enemyFishS);
      this.add(enemyFishS2);
      contact = false;
      win = false;
      repaint();
      Timer timer = new Timer();
      timer.schedule(new TimerTask() {

         @Override
         public void run() {
            if (enemyFishSFish.initiate == true) {
               randomFishSmall(enemyFishSFish, enemyFishS);// picks image and
                                                           // starting
                                                           // point/side
               enemyFishSFish.initiate = false;
            }
            if (enemyFishSFish.chooseSide == 0) {
               enemyFishSFish.moveLeft();
               if (enemyFishSFish.getX() < 5) {
                  enemyFishSFish.initiate = true;
               }
            } else if (enemyFishSFish.chooseSide == 1) {
               enemyFishSFish.moveRight();
               if (enemyFishSFish.getX() > 1295) {
                  enemyFishSFish.initiate = true;
               }
            }
            if (enemyFishSFish2.initiate == true) {
               randomFishSmall(enemyFishSFish2, enemyFishS2);// picks image and
                                                             // starting
                                                             // point/side
               enemyFishSFish2.initiate = false;
            }
            if (enemyFishSFish2.chooseSide == 0) {
               enemyFishSFish2.moveLeft();
               if (enemyFishSFish2.getX() < 5) {
                  enemyFishSFish2.initiate = true;
               }
            } else if (enemyFishSFish2.chooseSide == 1) {
               enemyFishSFish2.moveRight();
               if (enemyFishSFish2.getX() > 1295) {
                  enemyFishSFish2.initiate = true;
               }
            }
            enemyFishS.setLocation(enemyFishSFish.getX(), enemyFishSFish.getY());
            contact(enemyFishSFish);
            enemyFishS2.setLocation(enemyFishSFish2.getX(),
                  enemyFishSFish2.getY());
            contact(enemyFishSFish2);

            // contact(enemyFishSFish);
            // enemyFishS2.setLocation(enemyFishSFish2.getX(),enemyFishSFish2.getY());
            // enemyFishS3.setLocation(enemyFishSFish3.getX(),enemyFishSFish3.getY());
         }
      }, 0, 100);
      board.setState(Frame.ICONIFIED);
      board.setState(Frame.NORMAL);
   }

   public void mouseMoved(MouseEvent evt) {
      System.out.println(evt.getPoint().x + ", " + evt.getPoint().y);

      if ((evt.getPoint().x < 1231) && (evt.getPoint().y < 623)) {
         fish.setLocation(evt.getPoint().x, evt.getPoint().y);
         fishFish.override(evt.getPoint().x, evt.getPoint().y);
      }
      Timer timer = new Timer();
      timer.schedule(new TimerTask() {

         @Override
         public void run() {
            origin = fishFish.getX();
         }
      }, 0, 100);
      int posneg = origin - evt.getPoint().x;
      ImageIcon sfr = new ImageIcon("data/sfr.gif");
      ImageIcon sfl = new ImageIcon("data/sfl.gif");
      ImageIcon mfr = new ImageIcon("data/mfr.gif");
      ImageIcon mfl = new ImageIcon("data/mfl.gif");
      if (posneg < 0) {
         if (fishFish.sFish < 10)
            fish.setIcon(sfr);
         if (fishFish.sFish > 9)
            fish.setIcon(mfr);
      }
      if (posneg > 0) {
         if (fishFish.sFish < 10)
            fish.setIcon(sfl);
         if (fishFish.sFish > 9)
            fish.setIcon(mfl);
      }

   }

   public void mouseDragged(MouseEvent evt) {
   }

   // 95/34
   public void contact(fish enemyFish) {
      if ((Math.abs(fishFish.getX() - enemyFish.getX())) < 48
            && (Math.abs(fishFish.getY() - enemyFish.getY()) < 36)
            && (fishFish.sFish < 10)) {
         fishFish.sFish++;
         enemyFish.initiate = true;
      }
   }

   public void paintComponent(Graphics g) {
      super.paintComponent(g);
      background = new ImageIcon("data/background3.png");
      winBackground = new ImageIcon("data/");
      loseBackground = new ImageIcon("data/");
      if ((contact == false) && (win == false))
         g.drawImage(background.getImage(), 0, 0, null);
      if (contact == true)
         g.drawImage(loseBackground.getImage(), 0, 0, null);
      if (win == true)
         g.drawImage(winBackground.getImage(), 0, 0, null);
   }

   public void randomFishSmall(fish changeFishFish, JLabel changeFish) {
      int chooseType = (int) (Math.random() * 3);
      // int chooseType=2;
      int chooseSide = (int) (Math.random() * 2);// left=0right=1
      int chooseSpeed = (int) (Math.random() * 12) + 6;
      int choosePlacement = (int) (Math.random() * 1288) + 15;
      changeFishFish.chooseType = chooseType;
      changeFishFish.chooseSide = chooseSide;
      changeFishFish.chooseSpeed = chooseSpeed;
      changeFishFish.choosePlacement = choosePlacement;
      if (chooseType == 0) {
         if (chooseSide == 0) {
            changeFish.setIcon(fishSmall1l);
            changeFishFish.override(1300, choosePlacement);
            // changeFishFish.
         } else {
            changeFish.setIcon(fishSmall1r);
            changeFishFish.override(0, choosePlacement);
         }
         changeFish.setLocation(changeFishFish.getX(), changeFishFish.getY());
      } else if (chooseType == 1) {
         if (chooseSide == 0) {
            changeFish.setIcon(fishSmall2l);
            changeFishFish.override(1300, choosePlacement);
         } else {
            changeFish.setIcon(fishSmall2r);
            changeFishFish.override(0, choosePlacement);
         }
         changeFish.setLocation(changeFishFish.getX(), changeFishFish.getY());
      } else if (chooseType == 2) {
         if (chooseSide == 0) {
            changeFish.setIcon(fishSmall4l);
            changeFishFish.override(1300, choosePlacement);
            // changeFishFish.
         } else {
            changeFish.setIcon(fishSmall4r);
            changeFishFish.override(0, choosePlacement);
         }
         changeFish.setLocation(changeFishFish.getX(), changeFishFish.getY());
      }
   }
}

HTML的第一行应该返回:

Connection.Response res = Jsoup.connect(URL)
        .data("timezoneOffset", timeZoneOffset)
        .data("ptmode", ptMode)
        .data("ptlangcd", ptLangCD)
        .data("ptinstalledlang", ptInstalledLang)
        .data("userid", userID)
        .data("pwd", pwd)
        .data("ptlangsel", ptLangSel)
        .header("Host", HOST).userAgent(USER_AGENT)
        .header("Accept", ACCEPT)
        .header("Accept-Language", ACCEPT_LANGUAGE)
        .header("Accept-Encoding", ACCEPT_ENCODING)
        .referrer(REFERER)
        .method(Connection.Method.POST)
        .execute();

Document document = res.parse();
System.out.println(document);

但它会返回:

<html dir="ltr" lang="fr-ca" class='firefox win pc standard'>

我真的很感激任何建议,甚至是正确方向的暗示。

谢谢!

1 个答案:

答案 0 :(得分:0)

触发您喜爱的浏览器并打开开发人员工具栏中的“网络”标签。

检查浏览器和服务器之间交换的标头。

完成后,请在代码中执行相同操作。