gpt4 book ai didi

java - 使用 Jsoup 获取所有网络数据

转载 作者:行者123 更新时间:2023-12-02 02:46:46 27 4
gpt4 key购买 nike

我尝试获取所有数据网站,但出现错误行文档 doc1 = Jsoup.connect(url).get();你帮帮我吧!

public static void main(String[] args) throws IOException {
File file = new File("out22.txt");
FileWriter fw = new FileWriter(file);
PrintWriter pw = new PrintWriter(fw);

Document doc = Jsoup.connect("https://vnexpress.net/").get();
String title = doc.title();
System.out.println("Title : " + title);
Elements links = doc.select("a[href]");
for (Element link: links) {
String url = link.attr("href");
//System.out.println("\nLink: "+url);

Document doc1 = Jsoup.connect(url).get();
Elements title1 = doc1.select("h1[class=title_news_detail mb10]");
Elements description = doc1.select("p[class=description]");
Elements content = doc1.select("p[class=Normal]");
String tieude = title1.text();
String noidung = content.text();
String mota = description.text();
System.out.println(noidung);

pw.println(tieude);
pw.println("\n" + mota);
pw.println("\n" + noidung);
pw.close();

最佳答案

您的 URL 使用请求 header 进行过滤器连接。如果你想从中获取数据,你应该使用selenium。

关于java - 使用 Jsoup 获取所有网络数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57138740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com