Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:27:00+00:00 2026-06-07T15:27:00+00:00

I made a method that retrieves certain data from an Ebay search. Here is

  • 0

I made a method that retrieves certain data from an Ebay search. Here is the code that I am using:

public static LinkedList<EbaySearchResult> getResults(String search){
    LinkedList<EbaySearchResult> results = new LinkedList<EbaySearchResult>();
    LinkedList<String> links = new LinkedList<String>();
    LinkedList<String> titles = new LinkedList<String>();
    LinkedList<String> prices = new LinkedList<String>();
    LinkedList<String> images = new LinkedList<String>();
    try{
        Scanner reader = new Scanner(new URL(String.format("http://www.ebay.com/sch/i.html?_trksid=p5197.m570.l1313&_nkw=%s&_sacat=0", search)).openStream());
        while(reader.hasNextLine()){
            String line = reader.nextLine().trim();
            if(line != null && !line.equals("")){
                if(line.contains(CONTAINS_ONE) && line.contains(CONTAINS_TWO)){
                    String[] splitter = line.split(CONTAINS_SPLIT);
                    String[] splitter2 = splitter[1].split(CONTAINS_SPLIT_2);
                    images.add(splitter2[0].trim());
                }
                if(line.contains(INFO_CONTAINS)){
                    String[] splitter = line.split(INFO_SPLIT);
                    String[] splitter2 = splitter[1].split(INFO_SPLIT_2);
                    String[] splitter3 = splitter[1].split(INFO_SPLIT_3);
                    String[] splitter4 = splitter3[1].split(INFO_SPLIT_4);
                    links.add(splitter2[0].trim());
                    titles.add(splitter4[0].trim());
                }
                if(line.equalsIgnoreCase(PRICE_INFO)){
                    String next = reader.nextLine().trim();
                    String[] splitter = next.split(PRICE_SPLIT);
                    String[] splitter2 = splitter[1].split(PRICE_SPLIT_2);
                    prices.add(splitter2[0].trim());
                }
                if(line.contains(PRICE_EXTENDED_INFO)){
                    String[] splitter = line.split(PRICE_SPLIT);
                    String[] splitter2 = splitter[1].split(PRICE_SPLIT_2);
                    prices.add(splitter2[0].trim());
                }
            }
        }
        if(!links.isEmpty()){
            try{
            for(int i = 0; i < prices.size(); i++){
                if(titles.get(i) != null && prices.get(i) != null && links.get(i) != null && images.get(i) != null){
                    final String title = titles.get(i);
                    final String price = prices.get(i);
                    final String link = links.get(i);
                    final String image = images.get(i);
                    results.add(new EbaySearchResult(title, price, link, image));
                }
            }
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }catch(Exception e){
        e.printStackTrace();
    }
    return results;
}

The problem is is that my internet keeps dropping for, literally, a split second. I’ve tried searching other questions on this site for “how to check if you’re still connected”, or something similiar. I’ve tried multiple methods but none of the methods seem to work for me. The problem is is that when my internet drops for that split second, the whole method seems to break, and becomes useless (it seems that the Scanner does not automatically recover). What I want to do is add in a check to see if I’m still connected to the site, and if I’m not, I basically want to loop back to the beginning (I know how to do the looping part, but I just need the method that checks for whether or not I am connected) Any help would be greatly appreciated.

NOTE: There are no stack traces.

EDIT: I know that it is still running and the method is stalling because when I look at my console, the program is still running and basically all the code that is inside my main method, is actually calling the method ‘getResults’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:27:02+00:00Added an answer on June 7, 2026 at 3:27 pm

    You could just put a loop around your try/catch block and terminate when you want to stop reading from Ebay. If you get disconnected, the stream should throw an exception when you try to read from it, the exception gets caught, and at this point (maybe in a finally{}) make sure your resources are freed, then it loops back to the top of the try{} where a new Scanner is created and a new connection is made.

    By making sure the resources are freed, you probably want an InputStream declaration outside of the try block, and set it to the Url.openStream() call so that you can call close() on the input stream in a finally{} block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The first time I made a method to read data from my chat server,
HI I made a method in my class that is: public void addInfo(String username,
Currently I'm using the following extension method that I made to retrieve the values
I have made simple encryption/decryption method in php that I'm trying to move to
I've made a very simple REST controller method with Spring 3.0.0.RC1 that uses hibernate
I'm building a plugin using Firebreath. I made a personal method in ABCPluginAPI.cpp called
I have made a form validation using ajax post method. But i got the
I am working on a class library that retrieves information from a third-party web
I want to retrieve the email address from the table and using that to
We have a static method in a utility class that will download a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.