RuoYi-Cloud/xjs-business/xjs-business-webmagic/src/test/java/httpcilent/JsoupFirstTest.java

86 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package httpcilent;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URL;
/**
* @author xiejs
* @since 2022-01-27
*/
public class JsoupFirstTest {
@Test
public void testUrl() throws IOException {
//解析url地址 第一个参数访问的url第二个参数是超时时间
Document document = Jsoup.parse(new URL("http://www.itcast.cn"),
1000);
//使用标签选择器
String text = document.getElementsByTag("title").first().text();
System.out.println(text);
}
@Test
public void testDom() throws IOException {
Document document = Jsoup.parse(new URL("http://www.itcast.cn"),
1000);
Elements a_name = document.getElementsByClass("a_name");
System.out.println(a_name.first().text());
}
@Test
public void testData() throws IOException {
Document document = Jsoup.parse(new URL("http://www.itcast.cn"),
1000);
}
}