我和我的朋友需要帮助,我们正在尝试为学校项目创建一个小应用程序。首先,这个应用程序的目的是找到我们住的地方的药房。这两个是我试图从其中提取信息的网站(在这家名为拉?)我们如何从这些网页解析信息?
http://www.istanbulsaglik.gov.tr/w/nobet/liste.asp?lc=0&gun=09.05.2015
枪=天/日期
LC =镇
ID
cs每天都会给一个城镇,每天都在变化,这只是一个数字。
在这个页面上。
AND/OR
http://www.nobetcieczanebul.com/
这一个 '看起来' 更容易获得所需的信息。从。
它们都包含我需要的信息;药房的名称,地址和电话号码。通过使用JSOUP,我希望解析(拉?)这些信息,但我需要帮助。我的首要任务是使用'webview'。
首先,我们将从HTML读取cs,然后我们将cs放入代码并调用药店的所有名称,日期和地址。
这里是我的示例代码,这一个来电ID 32日镇的2015年5月5日包含名称等
import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
Button btnGetir;
ProgressBar pb;
TextView tv;
Button btnNobet;
TextView tvNobet;
WebView wv;
class mytask extends AsyncTask<Void,Void,Void>{
String Title;
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
pb.setVisibility(View.INVISIBLE);
tv.setText(Title);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pb.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... params) {
try {
Document myDoc= Jsoup.connect("http://www.ticaret.edu.tr").get();
Title=myDoc.title();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
class myNobettask extends AsyncTask<Void,Void,Void>{
String Title;
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
pb.setVisibility(View.INVISIBLE);
wv.loadData(Title, "text/html", "UTF-8");
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pb.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... params) {
try {
Document myDoc= Jsoup.connect("http://apps.istanbulsaglik.gov.tr/eczane/GetNobetciEczaneler.aspx?lc=32&gun=05.05.2015&cs=6e79f453").get();
Title=myDoc.html();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnGetir=(Button) findViewById(R.id.btnTitleGetir);
tv=(TextView)findViewById(R.id.tvSonuc);
pb=(ProgressBar) findViewById(R.id.progressBar);
btnNobet =(Button)findViewById(R.id.btnNobetci);
tvNobet=(TextView)findViewById(R.id.tvNobetci);
wv=(WebView) findViewById(R.id.webView);
btnGetir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mytask newtask= new mytask();
newtask.execute();
}
});
btnNobet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myNobettask task= new myNobettask();
task.execute();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
是必须使用本网站之一? ,因为您可以使用Google Places API,效率更高,并提供json o xml响应(易于解析) –
我“相信”,因为我们正在努力寻找药房值班。不知道这是否是正确的说法,值班药房 - >全天开放的药店,紧急药房。这两个网站就是展示它的网站。 Google Places API会显示它们吗? –
以下是Google API提供的所有类型的列表:https://developers.google.com/places/supported_types –