package
com.example.testparser;
import
java.io.IOException;
import
java.net.MalformedURLException;
import
java.net.URL;
import
net.htmlparser.jericho.Element;
import
net.htmlparser.jericho.HTMLElementName;
import
net.htmlparser.jericho.Source;
import
android.app.Activity;
import
android.os.Bundle;
import
android.os.StrictMode;
import
android.widget.TextView;
public
class
MainActivity
extends
Activity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.setThreadPolicy(
new
StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
TextView textView = (TextView)findViewById(R.id.mainTextView);
textView.setText(getURLtoText(Url));
}
public
String getURLtoText(String UrlString) {
Source source =
null
;
String content =
null
;
try
{
source =
new
Source(
new
URL(UrlString));
source.fullSequentialParse();
Element table = source.getAllElements(HTMLElementName.TABLE).get(
0
);
Element tr = table.getAllElements(HTMLElementName.TR).get(
0
);
Element td = tr.getAllElements(HTMLElementName.TD).get(
0
);
content = td.getTextExtractor().toString();
content =
new
String(content.getBytes(source.getEncoding()),
"utf-8"
);
}
catch
(MalformedURLException e) {
e.printStackTrace();
}
catch
(IOException e) {
e.printStackTrace();
}
return
content;
}
}