[英]Parsing a webpage in Eclipse using Jsoup
Hi I'm new to Eclipse and coding in general, and have been attempting to make a simple app to improve my skills. 嗨,我是Eclipse和编码方面的新手,并且一直在尝试制作一个简单的应用程序来提高我的技能。 I've run into a bit of a snag trying to reproduce a table from a webpage in my app.
我在尝试从我的应用程序中的网页复制表格时遇到了一些麻烦。 I've spent hours consulting forums on how to do so but it just doesn't seem to work.
我已经花了很多时间在论坛上咨询如何操作,但是似乎不起作用。 I am attempting to parse the page using JSoup.
我正在尝试使用JSoup解析页面。 I have downloaded and imported Jsoup.
我已经下载并导入了Jsoup。 Here is the java I have at the moment:
这是我目前拥有的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());
}
}
}
}
I don't have anything special in the related xml code besides some layout info. 除了一些布局信息,我在相关的xml代码中没有什么特别的。 When I run the app on the virtual device I get nothing but a blank page.
当我在虚拟设备上运行该应用程序时,除了空白页面外,什么都没有。
Any help or advice would be greatly appreciated and please remember that i'm new at this. 任何帮助或建议,将不胜感激,请记住,我是新来的。
Thanks, 谢谢,
Kindly use ksoap2-android library.. 请使用ksoap2-android库。
example : - 例如:-
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;
in method 方法中
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.