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 8682397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:45:41+00:00 2026-06-12T21:45:41+00:00

I’m creating a a web page scraper. I’m attempting to fill a JTable from

  • 0

I’m creating a a web page scraper. I’m attempting to fill a JTable from data on the page, retrieved using XPath. I want the data for a single row put into an array.

{"Name","Phone","Address","City","State","Postal Code","Link"}

I retrieve the webpage into a string to be parsed. There are no \n’s(Sorry, I don’t know the proper word for this. New lines?)

Screenshot of program
The array represents the data in a column. The way I want to do it is to make it so it retrieves the individual data row that row, then inserts it into the array, then it’s placed into the JTable. Then the array is set to null, the process is repeated.

Another option which I REALLY do not want to have to deal with would be placing all of the individual cells into array lists for each column, then do a while loop. The issue with this is that a entry might return empty, which would mean the indexes might not be perfectly synced.

I’m a rather “new” programmer, with about 6 months of experience of actually doing most things on my own. I’m still working on building my methodology, however here I’m stuck.

I’m wondering what would be the best solution in this situation, there’s probably a better solution that I have not thought of.

This is not a raw code problem, rather a flow problem.

It’s messy, yes. However it was very easy for me to crawl using Google Docs’s xPath & ImportXML functions.

Here is what I would put in the cells:

Name:

=importxml("http://www.yellowpages.com/[location]/[type]","//a[@class='no-tracks url ']")

Address:

=importxml("http://www.yellowpages.com/[location]/[type]","//span[@class='street-address']")

Phone:

=importxml("http://www.yellowpages.com/[location]/[type]","//span[@class='business-phone phone']")

I didn’t do the others, however I know it’s possible.

Removed the HTML example for privacy reasons, sorry.

  • 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-12T21:45:43+00:00Added an answer on June 12, 2026 at 9:45 pm

    Generate an Object that best represents the data (array). Use the data from the array to construct the object and add the object to the table model…

    public class Data {
        private String name;
        private String phone;
        private String address;
        private String city;
        private String state;
        private String postalCode;
        private String link;
        public Data(String[] data) { 
            name = data[0];
            phone = data[1];
            address = data[2];
            city = data[3];
            state = data[4];
            postalCode = data[5];
            link= data[6];
        }
    
        public String getName() {
            return name;
        }
    
        public String getPhone() {
            return phone;
        }
    
        public String getAddress() {
            return address;
        }
    
        public String getCity() {
            return city;
        }
    
        public String getState() {
            return state;
        }
    
        public String getPostalCode() {
            return postalCode;
        }
    
        public String getLink() {
            return link;
        }
    }
    

    Create a table model that is capable of taking advantage of this data object…

    public class MyDataTableModel extends AbstractTableModel {
    
        private List<Data> dataList;
    
        public MyDataTableModel() {
            dataList = new ArrayList<Data>(25);
        }
    
        @Override
        public int getRowCount() {
            return dataList.size();
        }
    
        @Override
        public int getColumnCount() {
            return 7;
        }
    
        @Override
        public String getColumnName(int column) {
            String name = "??";
            switch (column) {
                case 0:
                    name = "Name";
                    break;
                case 1:
                    name = "Phone";
                    break;
                case 2:
                    name = "Address";
                    break;
                case 3:
                    name = "City";
                    break;
                case 4:
                    name = "State";
                    break;
                case 5:
                    name = "Postal Code";
                    break;
                case 6:
                    name = "Link";
                    break;
            }
            return super.getColumnName(column);
        }
    
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            Object value = null;
            Data data = dataList.get(rowIndex);
            switch (columnIndex) {
                case 0:
                    value = data.getName();
                    break;
                // Other case statements per column...
            }
            return value;
        }
    
        public void add(Data data) {
            dataList.add(data);
            int index = dataList.size() - 1;
            fireTableRowsInserted(index, index);
        }
    }
    

    Once you have a new Data object, use this models add method to add it to the model.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to construct a data frame in an Rcpp function, but when I
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.