저는 안드로이드 애플리케이션을 개발했습니다. 안드로이드 애플리케이션은 웹 페이지를 파싱하고 결과적으로 그림과 텍스트를 반환합니다. 그러나 고객에게 응용 프로그램 코드를 보여 주면 그는 더 쉬운 알고리즘을 사용하여 응용 프로그램을 작성해야한다고 말했습니다. 응용 프로그램은 picture-urls 및 text-urls를 찾은 다음 설립 된 URL을 사용하여 내용을 표시해야합니다. 그것을하는 방법?안드로이드에서 그림과 URL을 구하십시오.
이 내 응용 프로그램에서 구문 분석 클래스 :
public class NetworkConnect extends AsyncTask<String, Void, Void>
{
//Background processing
ProgressDialog parsingBar = ProgressDialog.show(StackParser.this, "Working...", "requesting to URL and parsing content", true, false);
protected Void doInBackground(String... arg)
{
try
{
Log.d(LOG_TAG, arg[0]);
Document doc;
Elements urls;
Elements data;
Intent intent = new Intent(StackParser.this, AvailableContent.class);
doc = Jsoup.connect(arg[0]).timeout(10000).get();
data = doc.getAllElements();
Log.d(LOG_TAG, "Data: " + data.toString());
stringData = doc.text();
Log.d(LOG_TAG, "String data: " + stringData.toString());
urls = doc.select("[href$=.png]");
imageURL = urls.get(0).attr("href");
Log.d(LOG_TAG, "imageURL = " + imageURL);
if(!stringData.equals(""))
{
intent.putExtra("Send to the content-activity", stringData);
intent.putExtra("Send imagesURLs to the content-activity", imageURL);
startActivity(intent);
finish();
}
else
{
intent.putExtra("Send to the content-activity", "empty");
startActivity(intent);
finish();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} //catch (InterruptedException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
//}
return null;
}
protected void onPostExecute(Void result)
{
//Убираем диалог загрузки
parsingBar.dismiss();
}
}
}
당신은에서 URL을 얻고있다 이 비동기 작업? ? –
@BalvinderSingh, 아니요,이 비동기 작업은 웹 페이지를 구문 분석합니다. – pragmus
Log.d (LOG_TAG, "imageURL ="+ imageURL); 무슨이 줄 인쇄 ?? –