1 year ago

#282452

test-img

Burçin Cimcoz

How can I fetch jsoup results in one row in JAVA?

My Code Is:

    final String URL = "https://www.soccerstats.com/results.asp?league=turkey&pmtype=bydate";
    try {
        final Document document = Jsoup.connect(URL).get();
        id = 0;
        Elements des = document.select(".odd");
        Element titl = document.selectFirst(".body-text");
        Elements rows = des.select("td");
        if (titl != null) {
            for (int i = 1; i < rows.size(); i++) { // first row is the col names so skip it.
                Element row = rows.get(i);
                final String date = row.select("td:nth-of-type(1)").text();
                final String loc = row.select("td:nth-of-type(2)").text();
                final String res = row.select("td:nth-of-type(3)").text();
                final String vis = row.select("td:nth-of-type(4)").text();
                final String ht = row.select("td:nth-of-type(6)").text();
                System.out.println(date + “ ” + loc + " " + res + " " + vis + " " + ht);
                id++;

My current output is:

Sat 14 Aug    
 F. Karagumruk   
  3 - 2  
   Gaziantep 
    
    (2-1)

I scrape data from web site, I am getting related texts, but texts are fetching with white spaces and/or one row down.(like pressing enter or using /n I guess).

How can I get above results in one row as below?

Date Home Team Score Away Team Half Time
Sat 14 Aug F. Karagumruk 3 - 2 Gaziantep (2-1)

java

html

web-scraping

jsoup

0 Answers

Your Answer

Accepted video resources