在使用“ Inspect element ”之后,我需要解析并存储此link中此2个表中的数据,网络向我显示表的请求:
我做了什么:
它不起作用,即使我尝试在我的导航器中打开这两个请求,它也不起作用,那么如何从这些表中获取数据,并将数据存储在java列表中? 这就是我做的:
Button Rechercher = (Button) findViewById(R.id.button);
Rechercher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
wv2.getSettings().setLoadsImagesAutomatically(true);
wv2.getSettings().setJavaScriptEnabled(true);
wv2.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv2.loadUrl(requestCTM);
TestHtmlParse parse = new TestHtmlParse();
parse.toJava(requestCTM, wv2.getSettings().getUserAgentString());
}
}
});
Classe Implementation
public class TestHtmlParse {
private Connection.Response response;
public ArrayList<String> toJava(String url, String useragent) {
ArrayList<String> downServers = new ArrayList<>();
Date date = new Date();
String URL1 = "http://billetterie.ctm.ma/site/select_voyages_aller?datev=03-06-2016&agen_dep=001&agen_dest=002&nbp=1&dater=03-06-2016&aller=AS&tpay=MA&q=1&_search=false&nd="+date.getTime()+"&rows=30&page=1&sidx=&sord=";
Document doc = null;
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
//first request
response = Jsoup.connect(url).userAgent(useragent).timeout(10000).method(Connection.Method.GET).execute();
Map<String, String> cookies = response.cookies();
// second request with cookie
doc = Jsoup.connect(URL1).userAgent(useragent).timeout(10000).cookies(cookies).get();
}
} catch (IOException e) {
e.printStackTrace();
}
}