gpt4 book ai didi

java - 获取桌面站点而非移动站点的页面源

转载 作者:行者123 更新时间:2023-12-02 12:57:15 25 4
gpt4 key购买 nike

是否可以获取网站的桌面版页面源而不是移动网站?我的代码:

 public void test() {
;
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url = "google.com";

// Request a string response from the provided URL.
button = (TextView) findViewById(R.id.buttoneins);

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
button.setText("Response is: " + response.substring(0,5532));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
button.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}

最佳答案

尝试覆盖public Map<String, String> getHeaders() .

 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
button.setText("Response is: " + response.substring(0,5532));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
button.setText("That didn't work!");
},
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");


return params;
}

});

关于java - 获取桌面站点而非移动站点的页面源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44392197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com