我想将parse jsoup用于所有html页面,这些页面在我的webview中加载。我知道,我用我的第一个开始页面做的很热。 例如,用户在jsoup解析器之后看到主页面,其中只包含新闻。
public class MainActivity extends Activity {
private WebView webView;
Button btnback ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnback = (Button) findViewById(R.id.backbutton);
webView = (WebView) findViewById(R.id.webView_act_viewer);
webView.getSettings().setJavaScriptEnabled(true);
webView.setInitialScale(100);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setSupportZoom(true);
View.OnClickListener oclBtnBack = new View.OnClickListener(){
@Override
public void onClick (View v){
webView.goBack();
}
};
btnback.setOnClickListener(oclBtnBack);
new LoadData().execute();
}
@Override
public void onBackPressed (){
if(webView.canGoBack()) webView.goBack();
else super.onBackPressed();
}
private class LoadData extends AsyncTask<Void,Void,Void>
{
String html=new String();
Document doc = null;
@Override
protected Void doInBackground(Void... params) {
try {
doc = Jsoup.connect("http://www.fly4free.pl/").timeout(100000).get();
} catch (IOException e) {
e.printStackTrace();
}
Elements alldivs=doc.select("div.entry");
html=alldivs.html();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
webView.loadDataWithBaseURL(null,html,
"text/html", "utf-8", null);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
}