e6a2b3436bcd21aa78ed90b1e0f37563 如何使用java代码,爬取页面特定内容_光影知识库

如何使用java代码,爬取页面特定内容

 时间:2024-10-12 21:52:53

1、确认目标我们要爬取的是“百度”首页中的 gif 动态图将它下载下来

如何使用java代码,爬取页面特定内容

3、依赖有了我们就开始编码吧第一步:先把“百度”首页所有的html元素内容全部爬下来

如何使用java代码,爬取页面特定内容

5、第三步:获取图片的网络路径

如何使用java代码,爬取页面特定内容如何使用java代码,爬取页面特定内容

7、代码都在这里了 : public static void main(String [] args) throws IOExceptio荏鱿胫协n { Document doc = Jsoup.connect("http://www.baidu.com/").get(); Elements select = doc.select(".index-logo-src"); int i = 1; java.net.URL url = null; for (Element element : select) { String src = element.attr("src"); src = src.substring(2); src = "http://" + src; url = new java.net.URL(src); DataInputStream dataInputStream = new DataInputStream(url.openStream()); FileOutputStream fileOutputStream = new FileOutputStream(new File("e:/img/" + (i) + ".gif")); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = dataInputStream.read(buffer)) > 0) { output.write(buffer, 0, length); } byte[] bytes = output.toByteArray(); fileOutputStream.write(output.toByteArray()); dataInputStream.close(); fileOutputStream.close(); i++; }}

  • excel中offset函数的使用技巧
  • Interior.ColorIndex = 28EXCEL表格vba属性简介
  • Excel Vba怎么防止修改工作表名称
  • 如何在excel工作表中的某行或某列标记重复内容
  • VBA单元格中如何生成弹出式菜单
  • 热门搜索
    嗓子有痰是怎么回事 鲢鱼怎么做好吃 英文我爱你怎么写 在职证明怎么开 怎么去 手心出汗是怎么回事 excel函数怎么用 论文大纲怎么写 皮肤怎么变白 玫瑰怎么折