Obtained IT articles from Yahoo News.
jdk14.0.1 jsoup-1.13.1.jar
Since the environment setting of vscode was not completed, jsoup was not loaded at first and an error occurred. Correspond by setting in the following file.
settings.json
"java.project.referencedLibraries": [
"lib/**/*.jar",
"C:\\path\\jsoup-1.13.1.jar"
],
demojava/demo3/Web.java
package demojava.demo3;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class Web {
public static void main(String[] args) throws IOException {
Document document = Jsoup.connect("https://news.yahoo.co.jp/topics/it").get();
Elements courses = document.select(".newsFeed_item_link");
for (Element course : courses) {
System.out.println(course.attr("href")+ " [[::]] " + course.text());
}
}
}
Recommended Posts