php抓取网页数据实例(我正在创建一个第三方java应用程序(桌面)(桌面))
优采云 发布时间: 2022-04-07 09:10php抓取网页数据实例(我正在创建一个第三方java应用程序(桌面)(桌面))
我正在创建一个需要连接到基于 php 的站点并登录以采集相关数据的第 3 方 Java 应用程序(桌面)。没有可访问的 Web 服务,没有 API,每个用户都有自己的安全登录。该站点使用 dojo(如果这很重要),我使用 javahttpclient 发送帖子。
HttpPost httppost = new HttpPost("https://thewebsite.net/index/login"); // .php ?
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
//initialize the response string
String nextpage = "";
try {
// Add nvps
List nameValuePairs = new ArrayList(3);
nameValuePairs.add(new BasicNameValuePair("", ""));
nameValuePairs.add(new BasicNameValuePair("login", "USER"));
nameValuePairs.add(new BasicNameValuePair("", ""));
nameValuePairs.add(new BasicNameValuePair("pass", "PASSWORD"));
nameValuePairs.add(new BasicNameValuePair("Submit", ""));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
userID = EntityUtils.toString(response.getEntity());
System.out.println(nextpage);
httppost.releaseConnection();
}
...
现在,我遇到的问题是给我的响应是通过 dojo 为 user/pass 字段提供的验证 jscript。
dojo.require("dojox.validate._base");
function validate_RepeatPassword(val, constraints)
{
var isValid = false;
if(constraints) {
var otherInput = dijit.byId(constraints[0]);
if(otherInput) {
var otherValue = otherInput.value;
isValid = (val == otherValue);
}
}
return isValid;
}
我只想连接,解析一个 html 响应,然后关闭连接。
当我使用 firebug 时,我使用它作为 post 方法,但我似乎无法让它运行:quote login=user&pass=password