Siwoo Park
Siwoo Park

Reputation: 9

how can i do web scraping in this case?

i am trying to scrap text from https://in-the-sky.org/data/object.php?id=A216&day=17&month=6&year=2022 this is how the html of the part i want to scrap lookes like

this is the part i want to scrap

so i wrote a code like

import java.util.Iterator;
import org.jsoup.Jsoup;

import org.jsoup.nodes.Document;

import org.jsoup.nodes.Element;

import org.jsoup.select.Elements;



public class Main {
public static void main(String args[]) {

    int num = 216;
    int day = 17;
    int month = 6;
    int year = 2022;
    String url ="https://in-the-sky.org/data/object.php?id=A"+Integer.toString(num)+"&day="+Integer.toString(day)+"&month="+Integer.toString(month)+"&year="+Integer.toString(year);
    System.out.println(url);
    Document doc = null;
    
    try {
    
        doc = Jsoup.connect(url).get();
    
    } catch (Exception e) {
    
        // TODO: handle exception
        e.printStackTrace();
    
    }
    
    System.out.println("=======================================================");
    
    Elements element = doc.select("div.col-md-6 col-md-pull-6");  
    String output = element.select("p").text();
    System.out.println(output);
    
    
    System.out.println("=======================================================");
    
}
}

but it doesnt work well. i would like someone to help me please

Upvotes: 0

Views: 58

Answers (1)

TDG
TDG

Reputation: 6151

I believe that you can use Elements element = doc.select("div.col-md-6 > p"); to get your desired output.

Upvotes: 1

Related Questions