Home > Net >  how can i do web scraping in this case?
how can i do web scraping in this case?

Time:06-18

i am trying to scrap text from 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

CodePudding user response:

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

  • Related