Hello guys how are you all :D ?
im trying to scrape the search function from this website
https://mangairo.com/manga-list/type-topview/ctg-all/state-all/page-1
i can scrape its data imgs texts etc etc, but its too hard to scrape the serach function in that website.
i want you guys to guide me how to put that serach function in my app that view their data, im trying to make their website an app for me, i wont use webview haha its quite old,
my app is 99% finished it view/read the website with my own desgin, but search function is missing tell me how to scrape it and how to add it to my app, here is the codes, and ask me if something is missing that i did not mention. here is the xml main
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sifl="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="center"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="@string/abc_action_bar_up_description"
app:titleTextColor="#fff">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:divider="@color/colorAccent"
android:dividerPadding="6dp"
android:orientation="horizontal"
android:showDividers="end">
<ImageButton
android:id="@+id/toolbar_save"
style="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:drawableLeft="@drawable/ic_menus"
android:drawablePadding="0dp"
android:gravity="center_vertical"
android:onClick="opendrwer"
android:paddingBottom="6dp"
android:src="@drawable/ic_menus" />
<TextView
android:id="@+id/titlead"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="4dp"
android:paddingBottom="6dp"
android:text="Explore Manga"
android:textAlignment="center"
android:textColor="@color/cardview_light_background">
</TextView>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="@+id/recy"
android:background="@color/colorBackgorund"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
<com.example.myapplication.ScrimInsetsFrameLayout
android:id="@+id/drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:fitsSystemWindows="true"
sifl:insetForeground="#4000">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="24dp"
android:background="#673AB7">
</LinearLayout>
<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="256dp"
android:background="@mipmap/narutothumb3"
android:gravity="left|center_vertical"
android:orientation="vertical"
android:padding="8dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackgorund">
<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackgorund"
android:orientation="vertical">
<Button
android:id="@+id/Categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBackgorund"
android:gravity="left|center_vertical"
android:onClick="opengenre"
android:padding="8dp"
android:text="Categories"
android:textColor="#212121"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="@+id/Spoilers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBackgorund"
android:gravity="left|center_vertical"
android:onClick="openSpoilers"
android:padding="8dp"
android:text="Spoilers"
android:textColor="#212121"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="@+id/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF"
android:gravity="left|center_vertical"
android:onClick="AppTheme"
android:padding="8dp"
android:text="App theme"
android:textColor="#212121"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:alpha="0.5"
android:fontFamily="monospace"
android:text="version 1.0"
android:textColor="#212121"
android:textSize="10sp"
android:textStyle="bold"
android:typeface="sans" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</com.example.myapplication.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
and main java
package com.example.myapplication;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nightonke.boommenu.BoomButtons.ButtonPlaceEnum;
import com.nightonke.boommenu.BoomButtons.SimpleCircleButton;
import com.nightonke.boommenu.BoomMenuButton;
import com.nightonke.boommenu.ButtonEnum;
import com.nightonke.boommenu.Piece.PiecePlaceEnum;
import com.studioidan.httpagent.HttpAgent;
import com.studioidan.httpagent.StringCallback;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private TextView textViewl;
private RecyclerView recy;
private TextView textView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager layoutManager;
private List<PersonUtils> personUtilsList;
private int ints = 1;
private DrawerLayout Mdrawer;
private DatabaseTool databaseTool;
private ArrayList<HashMap<String, Object>> listmap = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewl = (TextView) findViewById(R.id.textview1);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setTitle("Latest Chapters");
databaseTool = new DatabaseTool();
init();
}
public void init() {
databaseTool.makeData(getFilesDir().getAbsolutePath(), "fav");
recy = (RecyclerView) findViewById(R.id.recy);
Mdrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
recy.setHasFixedSize(true);
textView = (TextView) findViewById(R.id.titlead);
layoutManager = new LinearLayoutManager(getApplicationContext());
recy.setLayoutManager(layoutManager);
personUtilsList = new ArrayList<>();
final Document[] document = new Document[1];
JSONArray array = new JSONArray();
//Get Document object after parsing the html from given url.
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Please Wait...");
dialog.setCancelable(false);
dialog.show();
JSONObject obj = new JSONObject();
String url = "https://mangairo.com/manga-list/type-topview/ctg-all/state-all/page-" + ints;
HttpAgent.get(url).
goString(new StringCallback() {
@Override
protected void onDone(boolean success, String results) {
dialog.cancel();
if (success) {
document[0] = Jsoup.parse(results);
//Get images from document object.
Elements images =
document[0].select(".story-list").get(0).children();
//Iterate images and print image attributes.
int iss = images.size();
iss = --iss;
for (int i = 0; i <= iss; i++) {
personUtilsList.add(new PersonUtils(images.get(i).getElementsByTag("img").attr("alt"),
images.get(i).child(2).text(), images.get(i).getElementsByTag("img").attr("src"), images.get(i).child(0).attr("href")));
}
;
mAdapter = new CustomRecyclerAdapter(getApplicationContext(), personUtilsList);
recy.setAdapter(mAdapter);
} else {
showMessage(getErrorMessage());
}
}
});
recy.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!recyclerView.canScrollVertically(1)) {
ints = ints + 1;
final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage("Please Wait...");
dialog.setCancelable(false);
dialog.show();
JSONObject obj = new JSONObject();
String url = "https://mangairo.com/manga-list/type-latest/ctg-all/state-all/page-" + ints;
HttpAgent.get(url).
goString(new StringCallback() {
@Override
protected void onDone(boolean success, String results) {
dialog.cancel();
if (success) {
List<PersonUtils> personUtils = new ArrayList<>();
document[0] = Jsoup.parse(results);
//Get images from document object.
Elements images =
document[0].select(".story-list").get(0).children();
//Iterate images and print image attributes.
int iss = images.size();
iss = --iss;
for (int i = 0; i <= iss; i++) {
personUtils.add(new PersonUtils(images.get(i).getElementsByTag("img").attr("alt"),
images.get(i).child(2).text(), images.get(i).getElementsByTag("img").attr("src"), images.get(i).child(0).attr("href")));
}
;
int insertIndex = mAdapter.getItemCount();
personUtilsList.addAll(insertIndex, personUtils);
mAdapter.notifyItemRangeInserted(insertIndex, personUtils.size());
showMessage("" + ints);
} else {
showMessage(getErrorMessage());
}
}
});
}
}
});
}
@SuppressLint("NewApi")
public void showMessage(String s) {
TextView te = new TextView(getApplicationContext());
te.setText("< " + s + ">");
LinearLayout layout2 = new LinearLayout(getApplicationContext());
layout2.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layout2.setOrientation(LinearLayout.HORIZONTAL);
layout2.setBackgroundResource(R.drawable.runded);
layout2.setElevation(8);
layout2.addView(te);
Toast to = new Toast(getApplicationContext());
to.setView(layout2);
to.setDuration(Toast.LENGTH_SHORT);
to.show();
}
@Override
protected void onDestroy() {
super.onDestroy();
clearApplicationData();
// Cancel running task(s) to avoid memory leaks
}
public void opendrwer(View view) {
try {
Mdrawer.openDrawer(Gravity.LEFT);
} catch (Exception e) {
Mdrawer.openDrawer(Gravity.RIGHT);
}
}
public void opengenre(View view) {
Intent intent = new Intent();
intent.setClass(getApplicationContext(), GenreActivity.class);
startActivity(intent);
}
public void clearApplicationData() {
File cache = getCacheDir();
File appDir = new File(cache.getParent());
if (appDir.exists()) {
String[] children = appDir.list();
for (String s : children) {
if (!s.equals("lib")) {
deleteDir(new File(appDir, s));
Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
}
}
}
}
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
public void clearcac(View view) {
}
public void openSpoilers(View view) {
Intent ddd = new Intent();
ddd.setClass(getApplicationContext(), Spoilers.class);
startActivity(ddd);
}
public void AppTheme(View view) {
Intent AppTheme = new Intent();
AppTheme.setClass(getApplicationContext(), AppTheme.class);
startActivity(AppTheme);
}
public void btnNightMode(View view){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
startActivity(new Intent(getApplicationContext(),MainActivity.class));
finish();
}
public void btnLightMode(View view){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
startActivity(new Intent(getApplicationContext(),MainActivity.class));
finish();
}
}