Soru & Cevap

Parser Sorunu Resimler görünmüyor ...

25.04.2017 - 09:40

Merhaba arkadaşlar Json parser ile bir gazete sitesinden veri çekmek istiyorum Burdan siteye bakabilirsiniz.. Sadece bulunan bölgedeki bir kaç görseli denemek için tek tek parser ettim..uygulamayı açtıgımda bilgiler geliyor lakin görseller parser edilmiyor.Herhangi birine tıkladıgımda ise açiliyor fakat büyük olarak degil.. bu konu hakkına eksik oldugumu biliyorum yardımcı olmanızı rica ediyorum usulca kodları aşagıya bırakıyorum.. :)

görsel link burda;

public class AnaSayfa extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anasayfa);
        TextView hurriyet_text= (TextView) findViewById(R.id.hurriyet_text);
        ImageView hurriyet_resim= (ImageView) findViewById(R.id.hurriyet_resim);
        String hurriyet_url="a[href=/gazete-mansetleri/hurriyet-gazetesi.html]";

        TextView sabah_text= (TextView) findViewById(R.id.sabah_text);
        ImageView sabah_resim= (ImageView) findViewById(R.id.sabah_resim);
        String sabah_url="a[href=/gazete-mansetleri/sabah-gazetesi.html]";

        TextView posta_text= (TextView) findViewById(R.id.posta_text);
        ImageView posta_resim= (ImageView) findViewById(R.id.posta_resim);
        String posta_url="a[href=/gazete-mansetleri/posta-gazetesi.html]";

        TextView haberturk_text= (TextView) findViewById(R.id.haberturk_text);
        ImageView haberturk_resim= (ImageView) findViewById(R.id.haberturk_resim);
        String haberturk_url="a[href=/gazete-mansetleri/haberturk-gazetesi.html]";

        TextView aksam_text= (TextView) findViewById(R.id.aksam_text);
        ImageView aksam_resim= (ImageView) findViewById(R.id.aksam_resim);
        String aksam_url="a[href=/gazete-mansetleri/aksam-gazetesi.html]";

        TextView vatan_text= (TextView) findViewById(R.id.vatan_text);
        ImageView vatan_resim= (ImageView) findViewById(R.id.vatan_resim);
        String vatan_url="a[href=/gazete-mansetleri/vatan-gazetesi.html]";

        TextView fanatik_text= (TextView) findViewById(R.id.fanatik_text);
        ImageView fanatik_resim= (ImageView) findViewById(R.id.fanatik_resim);
        String fanatik_url="a[href=/gazete-mansetleri/fanatik-gazetesi.html]";

        TextView fotomac_text= (TextView) findViewById(R.id.fotomac_text);
        ImageView fotomac_resim= (ImageView) findViewById(R.id.fotomac_resim);
        String fotomac_url="a[href=/gazete-mansetleri/fotomac-gazetesi.html]";


        LinearLayout hurriyet= (LinearLayout) findViewById(R.id.hurriyet);
        LinearLayout Sabah= (LinearLayout) findViewById(R.id.sabah);
        LinearLayout posta= (LinearLayout) findViewById(R.id.posta);
        LinearLayout haberturk= (LinearLayout) findViewById(R.id.haberturk);
        LinearLayout aksam = (LinearLayout) findViewById(R.id.aksam);
        LinearLayout vatan= (LinearLayout) findViewById(R.id.vatan);
        LinearLayout fotomac= (LinearLayout) findViewById(R.id.fotomac);
        LinearLayout fanatik= (LinearLayout) findViewById(R.id.fanatik);

        new Haberlerial(hurriyet_text,hurriyet_resim,hurriyet_url).execute();
        hurriyet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/hurriyet-gazetesi.html");
                startActivity(haberac);
        });

        new Haberlerial(sabah_text,sabah_resim,sabah_url).execute();
        Sabah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/sabah-gazetesi.html");
                startActivity(haberac);
            }
        });
        new Haberlerial(posta_text,posta_resim,posta_url).execute();
        posta.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/posta-gazetesi.html");
                startActivity(haberac);
            }
        });
        new Haberlerial(haberturk_text,haberturk_resim,haberturk_url).execute();
        haberturk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/haberturk-gazetesi.html");
                startActivity(haberac);
            }
        });
        new Haberlerial(aksam_text,aksam_resim,aksam_url).execute();
        aksam.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/aksam-gazetesi.html");
                startActivity(haberac);
            }
        });
        new Haberlerial(vatan_text,vatan_resim,vatan_url).execute();
        vatan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/vatan-gazetesi.html");
                startActivity(haberac);
            }
        });
        new Haberlerial(fanatik_text,fanatik_resim,fanatik_url).execute();
        fanatik.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/fanatik-gazetesi.html");
                startActivity(haberac);
            }
        });
        new Haberlerial(fotomac_text,fotomac_resim,fotomac_url).execute();
        fotomac.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent haberac=new Intent(AnaSayfa.this,GazeteAc.class);
                haberac.putExtra("gazeteurlsi", "http://www.gazeteoku.com/gazete-mansetleri/fotomac-gazetesi.html");
                startActivity(haberac);
            }
        });
    }


    protected class Haberlerial extends AsyncTask<Void, Void, Void> {
        String alınangazeteadi,resimurl,ParseEdilecekGazeteUrlsi;
        TextView gazeteadi;
        ImageView resim;
        String url = "http://www.gazeteoku.com/gazete-mansetleri.html";

        public Haberlerial(TextView text, ImageView resim, String url) {
            this.gazeteadi=text;
            this.resim=resim;
            this.ParseEdilecekGazeteUrlsi=url;
            

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
        @Override
        protected Void doInBackground(Void... params) {
            try {
                Document doc = Jsoup.connect(url).get();
                Elements gazetelerisec = doc.select("div[class=ssGList]");
                Elements gazeteyisec = gazetelerisec.select(ParseEdilecekGazeteUrlsi);
                Elements secilengazete = gazeteyisec.select("img[src]");
                resimurl = secilengazete.attr("src");
                alınangazeteadi= secilengazete.attr("alt");

            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        @Override
        protected void onPostExecute(Void aVoid) {

            gazeteadi.setText(alınangazeteadi);
            Picasso.with(AnaSayfa.this).load("http://www.gazeteoku.com"+resimurl).into(resim);
            
        }
    }

}

 

19 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-68435-1491411664.jpg
sametaylak
25.04.2017 - 09:58

Merhaba Osman,

"a[href=/gazete-mansetleri/hurriyet-gazetesi.html]" css querysi ile gazetelerin resimlerine maalesef ulaşılamıyor.

"a[href=/gazete-mansetleri/hurriyet-gazetesi.html] img" olarak ayrıca resimlere ulaşabilirsin. Geriye kalan tek şey ise gelen elementin src özelliğini çekmen olacaktır.

Elements secilengazete = gazeteyisec.select("img[src]");

Elements secilengazete = gazeteyisec.select(ParseEdilecekGazeteUrlsi + " img");

 

   
Osman krkmzlr
25.04.2017 - 10:28
Samet Hocam.. TextView hurriyet_text= (TextView) findViewById(R.id.hurriyet_text); ImageView hurriyet_resim= (ImageView) findViewById(R.id.hurriyet_resim); String hurriyet_url="a[href=/gazete-mansetleri/hurriyet-gazetesi.html]"; bu satır üzerinde göstererk yaparsanız sevnırım.. img kodu ekledıkten sonra Elements secilengazete = gazeteyisec.select("img[src]"); = bu kod Elements secilengazete = gazeteyisec.select(ParseEdilecekGazeteUrlsi + " img"); = bu şekildemi degiştirlicek