Java I';如果我使用程序或浏览器,我会得到不同的网站源代码
通过这段代码,我试图获得完整的源代码:Java I';如果我使用程序或浏览器,我会得到不同的网站源代码,java,html,http,cookies,web,Java,Html,Http,Cookies,Web,通过这段代码,我试图获得完整的源代码: import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Scanner; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.eve
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class URLConnectionReader extends Application {
public static void main(String[] args) {
launch(args);
}
TextArea ta;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
System.out.println("hallo");
System.exit(0);
}
});
Button btn = new Button();
System.out.println("1");
btn.setText("Go!");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("2");
try {
show();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Hello World!");
}
});
ta = new TextArea();
ta.setFocusTraversable(false);
ta.setEditable(false);
HBox comps = new HBox();
comps.getChildren().add(btn);
comps.getChildren().add(ta);
StackPane root = new StackPane();
root.getChildren().add(comps);
primaryStage.setScene(new Scene(root, 900, 950));
primaryStage.show();
}
@SuppressWarnings("resource")
public void show() throws IOException {
System.out.println("3");
URL url = new URL(
"http://www.backpack.tf/classifieds?quality=6&tradable=1&craftable=1&australium=-1&quality=5");
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
Scanner scanner = new Scanner(new InputStreamReader(conn.getInputStream()));
System.out.println("4");
while (scanner.hasNextLine()) {
ta.appendText(scanner.nextLine() + "\n");
System.out.println(scanner.nextLine());
}
}
import java.io.IOException;
导入java.io.InputStreamReader;
导入java.net.URL;
导入java.net.URLConnection;
导入java.util.Scanner;
导入javafx.application.application;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.control.TextArea;
导入javafx.scene.layout.HBox;
导入javafx.scene.layout.StackPane;
导入javafx.stage.stage;
导入javafx.stage.WindowEvent;
公共类URLConnectionReader扩展应用程序{
公共静态void main(字符串[]args){
发射(args);
}
文本区域ta;
@凌驾
公共无效开始(阶段primaryStage){
setTitle(“你好,世界!”);
setOnCloseRequest(新的EventHandler()){
@凌驾
公共无效句柄(WindowEvent事件){
System.out.println(“哈罗”);
系统出口(0);
}
});
按钮btn=新按钮();
系统输出打印项次(“1”);
btn.setText(“开始!”);
btn.setOnAction(新的EventHandler。
该程序显示一个输出,但如果我用firefox打开同一页并查看网站的源代码,它会更长。我如何才能让我的程序输出整个代码?我必须使用Cooices还是让用户代理更大?发送与浏览器完全相同的标题,并且您应该得到相同的响应。我建议使用F之类的工具iddler捕获浏览器的会话,然后尝试设置与浏览器完全相同的标题。一个接一个。好的,这样做了。现在我甚至没有HTML代码,但类似这样:?:ST3ùùú™C1‡HËvD+pÐTÎcÎmU/
)$UÐA|A&'XÎB½(“发送与浏览器完全相同的标题,您应该得到相同的响应。我建议使用像Fiddler这样的工具捕捉浏览器会话,然后尝试设置与浏览器完全相同的标题。一个接一个。好的,这样做了。现在我甚至没有得到HTML代码,但像这样:?:ST3úùú™C1-H-vD+p-TÎc-mU/
)$U-A | A&'XÎ0ýyÎB½(“?÷‡×/”c | WØ›«J»V§§§§¨3k²I++