【发布时间】:2014-04-20 09:00:33
【问题描述】:
我需要一些帮助,因为每次我尝试解决问题时都会遇到错误。我是android编程的新手。我想从 html 网站的某个字段中提取一个值。这个字段在一个表单中并且它被隐藏了。 html在这里。
<form autocomplete="off" id="Form1" action="login.aspx" method="post" name="Form1">
<input type="hidden" value="" name="__EVENTTARGET">
<input type="hidden" value="" name="__EVENTARGUMENT">
<input type="hidden" value="dDwtMTg3MDkxXN199v0w==" name="__VIEWSTATE">
我尝试编写一些代码,但目前我的 asynctask 出现错误。在使用 asynctask 之前,应用程序一直在崩溃,我发现故障可能是服务器需要一些时间来响应,这会导致一些问题。我的代码如下。
目的是使用 post 方法将这个值与用户名和密码一起发送到站点,然后检查它是否使用 post 方法发送和发送一些其他值。
请帮帮我!非常感谢您的宝贵时间!
package com.example.parser;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Connection().execute();
//TextView myText = (TextView) findViewById(R.id.textView1);
//myText.setText("value =" + value);
textView1 = (TextView) findViewById(R.id.textView1);
// try {
// parsing();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public static void parsing(TextView textView1) throws IOException {
Document doc = Jsoup.connect(
"i have hidden my url :p ").get();
Elements value = doc.select("[name=__VIEWSTATE]");
textView1.setText("my value is" + value);
}
private class Connection extends AsyncTask {
@Override
protected Object doInBackground(Object... arg0) {
try {
parsing(textView1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
}
【问题讨论】:
标签: android html parsing android-asynctask