почему я получаю разные html с одним и тем же URL android? - PullRequest
0 голосов
/ 14 июля 2020

, поэтому я пытаюсь получить html для этого URL https://store.playstation.com/en-us/grid/search-game/1?gameContentType=demos&platform=ps3&query=minecraft

Я получаю другое html с моего устройства, но когда я получаю html со своего компьютера, все в порядке .

я получаю html с этим кодом

public class DownloadTask extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... urls) {

            String result = "";
            URL url;
            HttpURLConnection urlConnection = null;

            try {
                url = new URL(urls[0]);
                urlConnection = (HttpURLConnection) url.openConnection();
                urlConnection.connect();

                InputStream in = urlConnection.getInputStream();
                InputStreamReader reader = new InputStreamReader(in);
                int data = reader.read();


                while (data != -1 && !result.contains("</script>")) {
                    char current = (char) data;
                    result += current;
                    data = reader.read();
                }

                return result;

            } catch (Exception e) {
                e.printStackTrace();
                return "Failed";
            }
        }

это результат из Интернета (мой компьютер)

</title>
  <script type="application/ld+json" id="ember27063297" class="ember-view">{"@context":"http://schema.org","@graph":[{"@type":"Product","name":"Minecraft: PlayStation®3 Edition","category":"Demo","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-MINECRAFTPS30295/1545097712000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":0}],"sku":"UP4433-NPUB31419_00-MINECRAFTPS30295","description":"Imagine it, and you can build it! The critically acclaimed Minecraft comes to PlayStation®3 system. Create your very own game world and explore, build and conquer. When night falls the monsters appear"}]}
</script>

и это результат с моего телефона

</title>
      <script type="application/ld+json" id="ember27197014" class="ember-view">{"@context":"http://schema.org","@graph":[{"@type":"Product","name":"Minecraft: PlayStation®3 Edition","category":"Demo","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-MINECRAFTPS30295/1545097712000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":0}],"sku":"UP4433-NPUB31419_00-MINECRAFTPS30295","description":"Imagine it, and you can build it! The critically acclaimed Minecraft comes to PlayStation®3 system. Create your very own game world and explore, build and conquer. When night falls the monsters appear"},{"@type":"Product","name":"Minecraft The Incredibles Skin Pack","category":"Character","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-KSP0000000000044/1580204457000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":2.99}],"sku":"UP4433-NPUB31419_00-KSP0000000000044","description":"Grab your super suit and join the action with the Parr family and other heroes and villains in this incredible skin pack!&lt;br&gt;&lt;br&gt;&lt;br&gt;1-8 players&lt;br&gt;Network Players 2-8&lt;br&gt;&lt;br&gt;  Software subject to lic"},{"@type":"Product","name":"Minecraft Villains Skin Pack","category":"Add-On","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-KSP0000000000031/1580204459000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":2.99}],"sku":"UP4433-NPUB31419_00-KSP0000000000031","description":"Unleash your inner villain with a pack dripping in the devious, the dastardly and the downright despicable! Scoundrels and schemers, mischief-makers and malevolent masterminds - this pack has the lot."},{"@type":"Product","name":"Minecraft Moana Character Pack","category":"Character","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-KSP0000000000040/1580204455000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":2.99}],"sku":"UP4433-NPUB31419_00-KSP0000000000040","description":"Set sail with Moana, Maui &amp; all the crew from Motunui. How far will you go in Minecraft with this adventurous character set? You’re welcome!&lt;br&gt;&lt;br&gt;&lt;br&gt;1-8 players&lt;br&gt;Network Players 2-8&lt;br&gt;&lt;br&gt;  Soft"},{"@type":"Product","name":"Minecraft Builder’s Pack","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-KBP0000000000004/1580204874000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":16.99}],"sku":"UP4433-NPUB31419_00-KBP0000000000004","description":"Do you want a to be a master builder? Get going with this bundle of six fantastic Minecraft packs: Biome Settlers Skin Pack 1, Candy Texture Pack, Cartoon Texture Pack, Pattern Texture Pack, Plastic T"},{"@type":"Product","name":"Minecraft Merry Bundle","image":"https://store.playstation.com/store/api/chihiro/00_09_000/container/US/en/999/UP4433-NPUB31419_00-KBP0000000000005/1580204874000/image?w=50&amp;h=50&amp;bg_color=000000&amp;opacity=100&amp;_version=00_09_000","offers":[{"@type":"Offer","priceCurrency":"USD","price":6.99}],"sku":"UP4433-NPUB31419_00-KBP0000000000005","description":"PLEASE NOTE: if you already own some or all of the packs included here, you will still be charged the full price of this bundle regardless of any previous ownership. Tear off the tinsel and open up th"},{

я получаю разные JSON с тем же URL

все было хорошо, пока я не добавил эту часть gameContentType=demos&

проверяю URL и его право, я не знаю, где проблема, пожалуйста, помогите.

этот дополнительный код может помочь.

@Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

            Log.i("TAG", "onPostExecute:"+s);

            Pattern pattern = Pattern.compile("\\{\"@context\":\"http://schema.org\",(.*?)\\]\\}",Pattern.MULTILINE);
            Matcher matcher = pattern.matcher(s);


            if (matcher.find()) {
                String ss = matcher.group();
                Log.d("TAG", "here: " + ss);

                try {
                    JSONObject jsonObject = new JSONObject(ss);
                    JSONArray jsonArray = jsonObject.getJSONArray("@graph");

                    if (jsonArray.length() <= 0){
                        Toast.makeText(MainActivity.this, "No result found", Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.GONE);
                        textView.setText("No result found");
                        textView.setVisibility(View.VISIBLE);
                    }

                    for (int i = 0 ; i < jsonArray.length(); i++){
                        JSONObject object = jsonArray.getJSONObject(i);
                        String gameName = object.getString("name");
                        String imageUrl = object.getString("image");

                        JSONArray offers = object.getJSONArray("offers");
                        String price = offers.getJSONObject(0).getString("price");

                        price = "$" + price ;

                        if (price.equals("$0")){
                            price = "Free";
                        }

                        if (gameName.length() > 35){
                            String gamename2 = gameName.substring(0,35);
                            gameName = gamename2 +"......." ;
                        }

                        arrayList.add(new Game(imageUrl,gameName,price));
                        adapter.notifyDataSetChanged();

                        progressBar.setVisibility(View.GONE);
                        textView.setVisibility(View.GONE);

                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                    progressBar.setVisibility(View.GONE);
                }


            }else{
                progressBar.setVisibility(View.GONE);
                Log.d("TAG", "here: " + "cant find");
            }



        }

здесь я выполняю метод

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                platform = sharedPreferences.getString("platform","");
                contentType = sharedPreferences.getString("content","");
                Log.d("TAG", "onCreate:platform =  "+platform);
                Log.d("TAG", "onCreate:platform =  "+contentType);
                if (!isNetworkAvailable()){
                    textView.setText("No Network Available");
                    textView.setVisibility(View.VISIBLE);
                }else {
                    arrayList.clear();
                    progressBar.setVisibility(View.VISIBLE);
                    textView.setVisibility(View.GONE);
                    DownloadTask task = new DownloadTask();
                    String url = "https://store.playstation.com/en-us/grid/search-game/1?"+ contentType + platform + "query=" + query;
                    Log.d("TAG", "onQueryTextSubmit: platform url ="+url);
                    task.execute(url);
                }
                hideKey(searchView);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...