Nancy Khorevich
Nancy Khorevich

Reputation: 53

Jsoup get absolute url from file and parse

I want to load some txt file with links inside. I want to parse this links (some result - tags or so on) sequentially to list view. I start to try something like this (But my knowledge in JSOUP is poor).

 File input = new File("http://files.parsetfss.com/ce686da3-4464-47ec-ba73-24747f2da937/tfss-75cfc482-96ab-45f8-8d8b-80b40a5a0298-http.txt");
    try {
        Document doc = Jsoup.parse(input, "UTF-8", "http://vao-priut.ru/");

    } catch (IOException e) {
        e.printStackTrace();
    }

Upvotes: 0

Views: 113

Answers (1)

Pshemo
Pshemo

Reputation: 124235

If you have some file on server available via browser you can simply read it line by line. To do it you can use for instance URL class and Scanner. When you will read each line you can parse it like you want.

 URL input = new URL("http://files.parsetfss.com/ce686da3-4464-47ec-ba73-24747f2da937/tfss-75cfc482-96ab-45f8-8d8b-80b40a5a0298-http.txt");
 Scanner sc = new Scanner(input.openStream());

 while(sc.hasNextLine()){
     String link = sc.nextLine();

     //since each line contains link to some resource 
     //now you can use jsoup to parse it
     Document doc = Jsoup.connect(link).get();
     //here place rest of code responsible for parsing
     //...
 }

Upvotes: 1

Related Questions