# Basic loadStrings() Question

**URL:** https://discourse.processing.org/t/basic-loadstrings-question/32663
**Category:** Coding Questions
**Created:** [October 7, 2021, 1:22am UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663 "2021-10-07T01:22:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dtools22](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dtools22](https://discourse.processing.org/u/dtools22)
#### Post date: [October 7, 2021, 1:22am UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663/1 "2021-10-07T01:22:35Z")

</div>

Hello all,

So I’m messing around with some data and I came across an issue. I would like to get the table from the following URL

> **[2021 NFL Opposition & Defensive Statistics | Pro-Football-Reference.com](https://www.pro-football-reference.com/years/2021/opp.htm#advanced_defense)**
>
> 2021 NFL Opposition & Defensive Statistics

However the following code produces an error.

```auto
Table testtable;

void setup(){
  testtable = loadTable("https://www.pro-football-reference.com/years/2021/opp.htm#advanced_defense", "header");
  saveTable(testtable, "new.csv");
}

void draw(){
  
}

```

“IllegalArgumentException: No extension specified for this Table”

I just started messing around with URL links for loadTable() so I just don’t know what could be wrong. I’m sure it’s something basic but I just don’t know what.

Thank you for the help!

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [October 7, 2021, 3:39am UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663/2 "2021-10-07T03:39:15Z")

</div>

Are you going to be doing this for lots of these tables, or just this one? If only this one, I would suggest you get the data as a CSV file (there’s an option for this under the “Share & Export” menu at the top left of each table), and then parse it yourself.

---

<div class="post-metadata">

### Author: ![dtools22](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dtools22](https://discourse.processing.org/u/dtools22)
#### Post date: [October 7, 2021, 4:11am UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663/3 "2021-10-07T04:11:38Z")

</div>

Ideally lots of them.

I have been just taking the .csv files and using them but ideally I would like to try to access the site directly. Both to access more of the data faster and to go through the exercise.

---

<div class="post-metadata">

### Author: ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)
#### Post date: [October 7, 2021, 4:44am UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663/4 "2021-10-07T04:44:16Z")

</div>

my 2 cents i don’t think you include enough in the options (if what was served by the site was of any of the types available at least)

> For example, to use tab-separated data, include “tsv” in the options parameter if the filename or URL does not end in **.tsv**. Note: If an extension is in both places, the extension in the **options** is used.
> 
> If the file contains a header row, include “header” in the **options** parameter. If the file does not have a header row, then simply omit the “header” option.

you can read more about that [here](https://github.com/processing/processing/issues/2291)

the problem is the site doesn’t actually serve you a csv file and even a tsv or bin file so you would need to approach this in another way.

like if you change your code to this

```auto
Table testtable;

void setup(){
  testtable = loadTable("https://www.pro-football-reference.com/years/2021/opp.htm#advanced_defense", "header, csv");
  saveTable(testtable, "new.csv");
}

void draw(){
  
}

```

you can see that error is gone but now the data cannot be read because it isn’t actually a csv file being served and so there is a new error. i don’t have a solution for you (at least just yet) but maybe someone else will chime in. i just thought i’d point those things out.

---

<div class="post-metadata">

### Author: ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)
#### Post date: [October 7, 2021, 6:05am UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663/5 "2021-10-07T06:05:20Z")

</div>

so… you could use [jsoup](https://jsoup.org) to parse the website and grab the data to build a table and save that table… lol

here’s the code

```auto
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.internal.*;
import org.jsoup.parser.*;
import org.jsoup.safety.*;
import org.jsoup.select.*;
import org.jsoup.helper.*;

void setup() {
  String url = "https://www.pro-football-reference.com/years/2021/opp.htm#advanced_defense";
  Document doc;

  try {
    doc = Jsoup.connect(url).get();
  } catch (IOException e) {
    e.printStackTrace();
    doc = null;
  }

  if (doc != null) {    
    print(doc.title());

    Element table = doc.select("table[id=team_stats]").get(0);    
    Elements rows = table.select("tr");
    
    PrintWriter myCsv = createWriter("myCsvFile.cvs");
    
    for (int i = 2; i < rows.size(); i++) {
        Element row = rows.get(i);
        Elements cols = row.select("td");
        
        for(int j = 0; j < cols.size(); j++) {
          String colVal = cols.get(j).text();
          if(colVal.length() > 0) {
            print(colVal + ',');
            myCsv.print(colVal + ",");
          }
        }
        println();
        myCsv.println();
    }
    myCsv.flush();
    myCsv.close();
  }
}

```

edit: i had originally built and posted a version which created a new [Table](https://processing.org/reference/Table.html) from the website scraping but realised that’s pointless and you can just use the [PrintWriter](https://processing.org/reference/PrintWriter.html) instead. the csv file seems good to me. best of luck.

---

<div class="post-metadata">

### Author: ![dtools22](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dtools22](https://discourse.processing.org/u/dtools22)
#### Post date: [October 7, 2021, 12:04pm UTC](https://discourse.processing.org/t/basic-loadstrings-question/32663/6 "2021-10-07T12:04:45Z")

</div>

That error not recognizing the table as a CSV is what prompted my post 🙂

I actually did try to add the options as well before posting and wasn’t understanding the error. There was a different table on this site I was testing with and it actually had two heading rows at the top, so I thought that might be creating the error. It makes a bit more sense that they are not .csv files.

I’ve been writing data base projects in processing for a little while now but I’ve always been manually localizing the data first. I thought maybe the Pro Football Reference website would be a good place to start trying to communicate with web sources directly.

Thank you for the code, I’ll give this a shot!
