-
网络爬虫
含义就是自动抓取互联网信息的程序,
jsoup可以通过url获取到html源文件,源文件中包含着网站数据,我们可以解析html源文件的数据来获取需要的信息, -
开发步骤
1 引入jar包
2 使用jsonp获取网页html源文件,转化成Document对象
3 通过Document对象,获取需要的Element对象,
4 获取Element对象中的数据,
5 设置循坏自动爬取
public class CrawlerDemo {
//爬虫
public static void main(String[] args) {
//使用jsoup获取网页中的html源文件,转化成Document对象,
try {
Document parse = Jsoup.parse(new URL("https://pic.netbian.com/"), 5000);
System.out.println(parse); //输出的源文件数据信息
//通过document对象来获取需要element对象
Elements img = parse.getElementsByAttributeValue("alt", "天空小姐姐 黑色唯美裙子 厚涂画风 4k动漫壁纸");
Elements title = parse.getElementsByAttributeValue("title",