01/10/2018, 09:50

Cần giúp đỡ về Scraper

câu hỏi: lọc các tin tức trên web mà thầy đưa.
(thầy đưa là ile html)
và có code là như vậy.
thầy bảo thêm code vào. vậy cho mình hỏi cách làm như thế nào.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;

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) throws Exception
	{
		String content ="";
		BufferedReader br = new BufferedReader(new FileReader("vnexpress.html"));
		String line;
		while((line = br.readLine())!=null)
		{
			content +=line;
		}
		Document doc = Jsoup.parse(content);
		Elements page_news = doc.getElementsByClass("list_news");
		for(Element list_news: page_news)
		{
			Elements news = list_news.children();
			for(Element li:news)
			{
				Element h3 = li.getElementsByClass("title_news").first();
				Element a =  h3.getElementsByTag("a").first();
				String title = a.text();
				Element news_lead = li.getElementsByClass("news_lead").first();
				
				String new_content = news_lead.text();
			}
		}
	}

}
Mi Móm viết 11:59 ngày 01/10/2018

có ai giúp mình bài này được k

khui khui viết 11:58 ngày 01/10/2018

bạn có thể tham khảo trang này nè https://jsoup.org/cookbook/

Bài liên quan
0