Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to scrape the url for data and how to get data into objects from network?

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to scrape the url for data and how to get data into objects from network?

    I am have been wanting to learn programming outside of unix for a long time. I finally have a project and the drive to start. What i want to acccomplish is use my bluetooth barcode scanner in my kitchen to scan UPC codes of finished food products. These UPC codes will then be scraped against UPC Database | Free information on thousands of products.. This site offers an API for retreiving data in either XML or JSON. Throught a little digging i found that I JSON is the easier to work with, but this is where i get lost, i did some reading on json parsers and such, but i think i am really in over my head. I beleive my main issue is finding out how to scrape the url for data and then how to get the data into objects.

    My code so far:

    import javax.swing.JOptionPane;

    public class barcode {
    public static void main(String args[]) throws IOException{


    //Barcode read and append to URL
    String UPC;
    UPC = JOptionPane.showInputDialog("Enter UPC");
    String URL;
    URL = "http://www.upcdatabase.org/api/json/*personal API KEY*/";
    String barcode;
    barcode = URL + UPC;


    //Filewrite Process

    FileWriter fstream = new FileWriter("out.txt",true);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(barcode + System.getProperty("line.separator"));
    //Close the output stream
    out.close();
    Last edited by Deep_4; November 7th, 2012 at 12:44 PM.


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: A Network Administrator Learning Java. First Time. Be Gentle

    Also at stackoverflow

    Please if you are going to start a discussion in multiple places, post a link at each to all of the others. This will allow anyone participating in the discussion to know what else is being said. See, for instance, this post on the topic.

    ---

    Your program is reasonably challenging for someone starting out with programming, but not impossibly so and I only point that out so there is no misconception.

    Right from the start you should adopt standard Java programming conventions. The idea is that these conventions (which enhance readability) become a habit and, hence, effortless. Classes begin with a capital letter, and variables and methods with a lowercase one. So Barcode, upc etc.

    The code you posted is missing a couple of closing braces.

    But even once added it isn't exactly clear to me what the problem is. Does the code you posted compile? If not and there are compiler messages you can't understand, post them. Does it do what you expect? (and what is that?) If not, what *does* it do?

    (As a network administrator you must be tediously aware of "it doesn't wrok!" substituting for a problem description. The same applies with programming.)

    Or is the problem one of deciding on the overall approach? If so I think what you posted *is* a quite workable way to go: get the bar code, form the url, download the content from the server, parse it and spit out the product description. Either JSON or XML is parseable in Java I assume (If I were writing this I would probably opt for XML as being less tied to JavaScript which is a different language.) So it's a matter of implementing each step in Java: reading input from the barcode reader, reading from a url and parsing the resulting xml.

    Break it down and tackle each part separately addressing specific problems as they arise.

Similar Threads

  1. Learning Java
    By jblankinship in forum Member Introductions
    Replies: 1
    Last Post: October 14th, 2012, 04:14 PM
  2. Need some help, learning java!
    By thisguyrighthere in forum Object Oriented Programming
    Replies: 5
    Last Post: June 10th, 2012, 09:41 PM
  3. Learning Java
    By destruxion in forum Member Introductions
    Replies: 1
    Last Post: September 12th, 2011, 03:13 AM
  4. Learning Java
    By jgc1 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 6th, 2011, 06:17 PM
  5. Hello. Just Learning Java For Fun..
    By derekeverett in forum Member Introductions
    Replies: 1
    Last Post: March 18th, 2010, 04:24 PM

Tags for this Thread