0

嗨,我是 Eclipse 和一般编码的新手,并且一直在尝试制作一个简单的应用程序来提高我的技能。我在尝试从我的应用程序中的网页复制表格时遇到了一些障碍。我已经花了几个小时在论坛上咨询如何做到这一点,但它似乎不起作用。我正在尝试使用 JSoup 解析页面。我已经下载并导入了 Jsoup。这是我目前拥有的java:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Standingspage extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_standingspage);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.standingspage, menu);
    return true;
}

public static void main(String[] args) throws Exception {
    Document doc = Jsoup.connect("http://pcihl.ca/Statistics/RegularSeasonStandings").get();
    for (Element table : doc.select("table")) {
        for (Element row : table.select("tr")) {
            Elements tds = row.select("td");
            System.out.println(tds.get(0).text());   
        }
    }
}

    }

除了一些布局信息外,我在相关的 xml 代码中没有任何特别之处。当我在虚拟设备上运行应用程序时,我只得到一个空白页面。

任何帮助或建议将不胜感激,请记住我是新手。

谢谢,

4

1 回答 1

0

请使用 ksoap2-android 库..


例子 : -


private static final String NAMESPACE = YOUR_URL_IN_STRING;
    private static final String HEADER = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>";
    private static final int SOAP_VERSION = SoapEnvelope.VER11;

在方法中

long startTime=System.currentTimeMillis();
    String METHOD_NAME = "CheckDeviceRegistration";
    String SOAP_ACTION = NAMESPACE + METHOD_NAME;

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("deviceCode", deviceCode);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SOAP_VERSION); // put all required data into a soap envelope
    envelope.dotNet = true;
    // envelope.addMapping(NAMESPACE, "GetApplicationConfigurations", GetApplicationConfigurations.class);
    // envelope.headerOut = security; // this is an Element[] created before
    // envelope.encodingStyle = SoapEnvelope.ENC;
    envelope.setAddAdornments(false);
    envelope.implicitTypes = false;
    envelope.setOutputSoapObject(request); // prepare request

    HttpTransportSE httpTransport = new HttpTransportSE(URL, timeOut);

    httpTransport.debug = DEBUG; // this is optional, use it if you don't want to use a packet sniffer to check what the sent
                                    // message was (httpTransport.requestDump)
    httpTransport.setXmlVersionTag(HEADER);

    try {

        httpTransport.call(SOAP_ACTION, envelope);

    } catch (IOException e) {

        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } // send request
    Log.d("RAM RAM3", "XML: " + httpTransport.requestDump);
    SoapObject result = null;
    String returnString = "";
    try {
        envelope.getResponse();

        result = (SoapObject) envelope.bodyIn;
        returnString = result.getProperty(0).toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
于 2013-10-15T02:46:54.267 回答