Android SDK Android Basic JSOUP Tutorial

2017.03.27 15:27

졸리운_곰 조회 수:349

Android Basic JSOUP Tutorial

In this tutorial, you will learn how to implement JSOUP open source java library in your Android application. JSOUP provides a very convenient API for extracting and manipulating data, using DOM, CSS, and jquery-like methods. JSOUP allows you to scrape and parse HTML from a URL, file, or string and many more. We will create 3 buttons on the main view and each button will perform different tasks such as showing the website title, description and a logo. So lets begin…

 

Before you proceed with this tutorial, download the latest JSOUP library from here.

Paste your downloaded Jsoup file into your project libs folder as shown on the image below.

jsoup_libs

Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project JsoupTutorial.

Application Name : JsoupTutorial

Project Name : JsoupTutorial

Package Name : com.androidbegin.jsouptutorial

Open your MainActivity.java and paste the following code.

MainActivity.java

In this activity, we have created three buttons that response to three different AsyncTask. Before I proceed with further explanation, see the steps below on how to get the html source codes from a website.

Step 1 : Visit http://www.androidbegin.com with any preferred Internet browser on your PC

homepage

 

Step 2 : Right-Click on an open space and select “View page source

pagesource

 

Step 3 : Website source codes

source

 

A website source code determines how your webpages should appear. However, source code of a web page will only display information and code that is not processed by the server.

The first button retrieves the website title. This is a way to get the page title.

Java Code

Website Source Code

 

The second button retrieves the website description. By using Elements, we are able to specify the exact location of the data.

Java Code

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

Website Source Code 

 

The third button retrieves the website logo. By using Elements, we are able to specify the exact location of the data.

Java Code

Website Source Code

 

Next, create an XML graphical layout for the MainActivity. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file activity_main.xml and paste the following code.

activity_main.xml

Next, change the application name and texts. Open your strings.xml in your res > values folder and paste the following code.

strings.xml

In your AndroidManifest.xml, we need to declare permissions to allow the application to connect to the Internet. Open your AndroidManifest.xml and paste the following code.

AndroidManifest.xml

Output:

BasicJsoupTutorial ScreenShots

Source Code

JsoupTutorial.rar

JsoupTutorial.rar

 

[출처] http://www.androidbegin.com/tutorial/android-basic-jsoup-tutorial/

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
93 Android Studio Build시 failed linking references 해결방법 file 졸리운_곰 2020.05.05 648
92 [안드로이드 스튜디오] COULD NOT FIND COM.ANDROID.TOOLS.BUILD:GRADLE:3.0.0-BETA6 file 졸리운_곰 2020.05.05 125
91 Android Sync SQLite Database with Server using PHP and MySQL file 졸리운_곰 2019.02.25 7762
90 안드로이드의 MVC, MVP, MVVM 종합 안내서 file 졸리운_곰 2019.01.06 370
89 Getting Started: WebView-based Applications for Web Developers file 졸리운_곰 2018.09.03 410
88 App Inventor - MySQL interface 앱 인벤터 mysql 연결 file 졸리운_곰 2018.04.07 7995
87 Connect App Inventor to MySQL Database 앱 인벤터와 mysql 데이터베이스 연결 file 졸리운_곰 2018.04.07 7273
86 Create an API (PHP) 앱 인벤터와 php 통합 file 졸리운_곰 2018.04.07 630
85 Android WebView javascriptInterface 사용하기 file 졸리운_곰 2018.03.26 656
84 Using the WebViewer Control in App Inventor 앱인터에서 웹뷰 컨트롤 사용 file 졸리운_곰 2018.03.24 512
83 WebView Javascript Processor for App Inventor 앱 인벤터 웹뷰 자바스크립트 인터페이스 file 졸리운_곰 2018.03.24 505
82 android webview로 javascript 호출 및 이벤트 받기(연동하기) file 졸리운_곰 2018.03.19 1405
81 Android Asynchronous Http Client file 졸리운_곰 2017.07.03 709
80 안드로이드 에서 JSON 읽어오기 (JSON parser) file 가을의곰 2017.06.18 827
79 Creating a digital wallet application in App Inventor 2 file 졸리운_곰 2017.05.01 287
» Android Basic JSOUP Tutorial file 졸리운_곰 2017.03.27 349
77 [Android] 안드로이드 웹페이지 파싱하기 - jsoup 이용하기 file 졸리운_곰 2017.03.27 724
76 Android에서 jsoup를이용하여 HTML 파서(Parser) file 졸리운_곰 2017.03.27 764
75 Android : Keystore 정보확인 및 패스워드 변경 졸리운_곰 2017.03.23 235
74 android studio 2.3 의 안드로이드 레이아웃 배치 법 : Layout Editor로 UI 빌드 file 졸리운_곰 2017.03.09 534
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED