【发布时间】:2016-09-30 21:33:06
【问题描述】:
我和我的朋友在我们正在尝试为学校项目创建的一个小应用程序方面需要帮助。首先,此应用程序的目的是在我们居住的地方寻找药房。这两个是我试图从中提取信息的网站(这是否称为拉取?)
http://www.istanbulsaglik.gov.tr/w/nobet/liste.asp?lc=0&gun=09.05.2015
gun = 日期/日期
lc = 城镇 ID
cs 每天给一个城镇,每天都在变化,它只是一个数字。
在这个页面中。
与/或
http://www.nobetcieczanebul.com/
这个“看起来”更容易获得所需的信息。来自。
它们都包含我需要的信息;药房的名称,地址,可能还有电话号码。通过使用 JSOUP,我希望解析(提取?)这些信息,但我需要帮助。我的首要任务是使用“webview”。
首先我们从 HTML 中读取 cs,然后我们将 cs 放入代码中并调用所有药房的名称、日期和地址。
这是我的示例代码,此代码调用 id 32 town of date 05/05/2015 其中包含名称等。
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 可以提供的所有类型的列表:developers.google.com/places/supported_types
-
嗯,你说得对,我们可以使用它,你有任何示例代码可以嵌入到我们的代码中吗?
-
我会把它作为答案发布
标签: android html webview jsoup