2013-10-15 35 views
0

您好我是Eclipse的新手,一般编码,并且一直在尝试制作一个简单的应用程序来提高我的技能。我遇到了一些问题,试图从我的应用程序的网页中重现表格。我花了几个小时咨询论坛如何这样做,但它似乎并没有工作。我试图用JSoup解析页面。我已经下载并导入了Jsoup。这里是我目前的Java:使用Jsoup解析Eclipse中的网页

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代码,除了一些布局信息。 当我在虚拟设备上运行应用程序时,我什么也得不到,只有一个空白页面。

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

谢谢,

回答

0

请使用kso​​ap2-机器人库..


例如: -


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(); 
    }