Web Scraping With Jsoup in Sketchware

In this article I'm going to introduce you to this library to be familiar with it so we will walk through a simple steps so we won't get struck in the future 


jsoup is an open-source Java library designed to parse, extract, and manipulate data stored in HTML documents.


What does it mean 🤔🤔


It means that you can pick almost any website and extract data from it and use it as much as you want with no issues

Keep in mind that jsoup has problems with pages that use javascript to load data cause it is dynamically generated and jsoup can only handle the static data that provided in the html page


Sorry for long talk but I wanted to make sure that you understand what we are going to do


So before start you need :

👉 Sketchware Mod called Revolution in case you don't have it here is the  Link 🔗 

👉 Second you need library importer  
Link 

If you have both than you can start

👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇



Open your new Sketchware project 

And add a TextView 

Then add two strings variables
url
title

then in onCreate do this 
You can choose any url you like 


Then add request network component 


In onResponse add this


Codes :
Please follow the picture above or watch video carefully 

class AsyncTaskEx extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... arg0) {

org.jsoup.nodes.Document doc = org.jsoup.Jsoup.connect(url).get();

title = doc.title();

return null; }  /** The system calls this to perform work in the UI thread and delivers * the result from doInBackground() */ @Override protected void onPostExecute(Void result) {

return ; }

@Override protected void onPreExecute() {

return ; } }

new AsyncTaskEx().execute();


And after that just add jsoup library to your project and build it


Comments

Post a Comment