I am trying to do a website scraping app that, when an item is entered, will search a specific website for the product and return the price of a list of related items, for example Amazon. I have the code kind of working, except when the text is returned it only gives the price. Below is the code:
package com.start.layout;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton ;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.example.mf124.pricetackbenj.History;
import com.example.mf124.pricetackbenj.R;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Start extends AppCompatActivity
{
String title, wordentered;
Elements prices;
List my_array_list = new ArrayList();

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

getSupportActionBar().setDisplayHomeAsUpEnabled(tr ue);

Button searchwebsite = (Button) findViewById(R.id.SearchWeb);
searchwebsite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText tt = (EditText) findViewById(R.id.editText);

wordentered = tt.getText().toString();
new AsyncTaskRunner().execute();
}
});
}

public void oo()
{
ListView lv = (ListView) findViewById(R.id.listView);
ArrayAdapter arrayAdapter = new
ArrayAdapter(this,android.R.layout.simple_list_ite m_1,my_array_list);
lv.setAdapter(arrayAdapter);
}

private class AsyncTaskRunner extends AsyncTask
{
private String resp;

@Override
protected String doInBackground(String... params)
{
try
{
Document doc = Jsoup.connect("" + wordentered).get();
title = doc.title();
prices = doc.select("");
String newd = prices.toString();
my_array_list.add(title);
my_array_list.add(newd);
}
catch (IOException e)
{
e.printStackTrace();
}
return title;
}
@Override
protected void onPostExecute(String result) { oo(); }
}
}
It is displaying the price but not the item name, what am I doing wrong?


Check Solution