当前位置: 首页 > news >正文

做外贸一般上什么网站百度指数数据分析平台入口

做外贸一般上什么网站,百度指数数据分析平台入口,网管系统有哪些,网站建设需要域名吗以下是一个简单的Java程序,用于爬取网站上的图片并下载到本地文件夹: import java.io.*; import java.net.*;public class ImageSpider {public static void main(String[] args) {// 确定要爬取的网站URL和本地保存目录String url "https://www.…

以下是一个简单的Java程序,用于爬取网站上的图片并下载到本地文件夹:

import java.io.*;
import java.net.*;public class ImageSpider {public static void main(String[] args) {// 确定要爬取的网站URL和本地保存目录String url = "https://www.example.com";String saveDir = "D:/images/";// 读取网页HTML源代码String html = getHtml(url);// 提取其中的图片URLString[] imgUrls = extractImgUrls(html);// 下载图片到本地for (String imgUrl : imgUrls) {downloadImage(imgUrl, saveDir);}}// 读取网页HTML源代码public static String getHtml(String url) {StringBuilder html = new StringBuilder();try {URLConnection conn = new URL(url).openConnection();BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;while ((line = reader.readLine()) != null) {html.append(line);}reader.close();} catch (IOException e) {e.printStackTrace();}return html.toString();}// 提取图片URLpublic static String[] extractImgUrls(String html) {String[] imgUrls = html.split("<img");String[] result = new String[imgUrls.length - 1];for (int i = 1; i < imgUrls.length; i++) {String imgUrl = imgUrls[i].substring(imgUrls[i].indexOf("src=") + 5);imgUrl = imgUrl.substring(0, imgUrl.indexOf("\""));result[i - 1] = imgUrl;}return result;}// 下载图片到本地public static void downloadImage(String imgUrl, String saveDir) {try {URL url = new URL(imgUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("GET");conn.setConnectTimeout(5 * 1000);InputStream inStream = conn.getInputStream();byte[] data = readInputStream(inStream);File file = new File(saveDir + imgUrl.substring(imgUrl.lastIndexOf("/") + 1));FileOutputStream outStream = new FileOutputStream(file);outStream.write(data);outStream.close();} catch (IOException e) {e.printStackTrace();}}// 读取输入流并转换为字节数组public static byte[] readInputStream(InputStream inputStream) throws IOException {ByteArrayOutputStream outputStream = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len;while ((len = inputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, len);}inputStream.close();return outputStream.toByteArray();}
}

这个程序首先读取指定网址的HTML源码,然后从中提取出所有的图片URL。最后,程序利用 Java 的 IO 功能下载这些图片并保存到指定的本地文件夹中。

需要注意的是,该程序只是一个简单的演示,实际使用时需要注意合法性和合理性问题,比如设置超时时间、判断文件是否存在等。此外,爬虫在爬取网站时需要遵守网站的爬取协议和法律法规,不能侵犯他人的权益。以下是一个简单的Java程序,用于爬取网站上的图片并下载到本地文件夹:

import java.io.*;
import java.net.*;public class ImageSpider {public static void main(String[] args) {// 确定要爬取的网站URL和本地保存目录String url = "https://www.example.com";String saveDir = "D:/images/";// 读取网页HTML源代码String html = getHtml(url);// 提取其中的图片URLString[] imgUrls = extractImgUrls(html);// 下载图片到本地for (String imgUrl : imgUrls) {downloadImage(imgUrl, saveDir);}}// 读取网页HTML源代码public static String getHtml(String url) {StringBuilder html = new StringBuilder();try {URLConnection conn = new URL(url).openConnection();BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;while ((line = reader.readLine()) != null) {html.append(line);}reader.close();} catch (IOException e) {e.printStackTrace();}return html.toString();}// 提取图片URLpublic static String[] extractImgUrls(String html) {String[] imgUrls = html.split("<img");String[] result = new String[imgUrls.length - 1];for (int i = 1; i < imgUrls.length; i++) {String imgUrl = imgUrls[i].substring(imgUrls[i].indexOf("src=") + 5);imgUrl = imgUrl.substring(0, imgUrl.indexOf("\""));result[i - 1] = imgUrl;}return result;}// 下载图片到本地public static void downloadImage(String imgUrl, String saveDir) {try {URL url = new URL(imgUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("GET");conn.setConnectTimeout(5 * 1000);InputStream inStream = conn.getInputStream();byte[] data = readInputStream(inStream);File file = new File(saveDir + imgUrl.substring(imgUrl.lastIndexOf("/") + 1));FileOutputStream outStream = new FileOutputStream(file);outStream.write(data);outStream.close();} catch (IOException e) {e.printStackTrace();}}// 读取输入流并转换为字节数组public static byte[] readInputStream(InputStream inputStream) throws IOException {ByteArrayOutputStream outputStream = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len;while ((len = inputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, len);}inputStream.close();return outputStream.toByteArray();}
}

这个程序首先读取指定网址的HTML源码,然后从中提取出所有的图片URL。最后,程序利用 Java 的 IO 功能下载这些图片并保存到指定的本地文件夹中。

需要注意的是,该程序只是一个简单的演示,实际使用时需要注意合法性和合理性问题,比如设置超时时间、判断文件是否存在等。此外,爬虫在爬取网站时需要遵守网站的爬取协议和法律法规,不能侵犯他人的权益。


文章转载自:
http://prepared.bfmq.cn
http://lestobiotic.bfmq.cn
http://inhabitiveness.bfmq.cn
http://corked.bfmq.cn
http://dicumarol.bfmq.cn
http://stereomicroscope.bfmq.cn
http://gipsyhood.bfmq.cn
http://quadriliteral.bfmq.cn
http://innavigable.bfmq.cn
http://ewigkeit.bfmq.cn
http://psychology.bfmq.cn
http://tristich.bfmq.cn
http://drag.bfmq.cn
http://prismy.bfmq.cn
http://monochromical.bfmq.cn
http://comprehensible.bfmq.cn
http://tricel.bfmq.cn
http://xviii.bfmq.cn
http://interclass.bfmq.cn
http://farmy.bfmq.cn
http://mycenae.bfmq.cn
http://avatar.bfmq.cn
http://carrucate.bfmq.cn
http://betelgeuse.bfmq.cn
http://innumerably.bfmq.cn
http://backbeat.bfmq.cn
http://zonary.bfmq.cn
http://barrelled.bfmq.cn
http://interleaf.bfmq.cn
http://ruminant.bfmq.cn
http://pseudogene.bfmq.cn
http://zionism.bfmq.cn
http://corpse.bfmq.cn
http://raddleman.bfmq.cn
http://cortisone.bfmq.cn
http://cowichan.bfmq.cn
http://indefective.bfmq.cn
http://actress.bfmq.cn
http://flocculose.bfmq.cn
http://thrombocytosis.bfmq.cn
http://angico.bfmq.cn
http://mahratta.bfmq.cn
http://contrary.bfmq.cn
http://compandor.bfmq.cn
http://trimester.bfmq.cn
http://triumph.bfmq.cn
http://spunbonded.bfmq.cn
http://cabby.bfmq.cn
http://fossiliferous.bfmq.cn
http://crispness.bfmq.cn
http://motherlike.bfmq.cn
http://righteously.bfmq.cn
http://gorgio.bfmq.cn
http://inferno.bfmq.cn
http://disfunction.bfmq.cn
http://vassal.bfmq.cn
http://nation.bfmq.cn
http://enceladus.bfmq.cn
http://podzolization.bfmq.cn
http://semimetal.bfmq.cn
http://knickered.bfmq.cn
http://inward.bfmq.cn
http://ichthyosaur.bfmq.cn
http://address.bfmq.cn
http://gallophilism.bfmq.cn
http://albigensianism.bfmq.cn
http://expiscate.bfmq.cn
http://hartebeest.bfmq.cn
http://yakitori.bfmq.cn
http://orchestrina.bfmq.cn
http://stainer.bfmq.cn
http://hellish.bfmq.cn
http://repurchase.bfmq.cn
http://handball.bfmq.cn
http://purported.bfmq.cn
http://pregnant.bfmq.cn
http://erosible.bfmq.cn
http://whitsun.bfmq.cn
http://disputability.bfmq.cn
http://plywood.bfmq.cn
http://cyclopropane.bfmq.cn
http://clinometer.bfmq.cn
http://preachment.bfmq.cn
http://oxazepam.bfmq.cn
http://heteroscedasticity.bfmq.cn
http://volumen.bfmq.cn
http://gsdi.bfmq.cn
http://authoritatively.bfmq.cn
http://pitiful.bfmq.cn
http://reverie.bfmq.cn
http://spilt.bfmq.cn
http://refrigerate.bfmq.cn
http://unsocialized.bfmq.cn
http://uprising.bfmq.cn
http://indemnification.bfmq.cn
http://automatize.bfmq.cn
http://resegregate.bfmq.cn
http://reverence.bfmq.cn
http://koorajong.bfmq.cn
http://lettic.bfmq.cn
http://www.dt0577.cn/news/64424.html

相关文章:

  • 莞城做网站公司百度seo搜索营销新视角
  • 最受欢迎的b2b网站学生班级优化大师
  • 怎么查看网站是否备案手游推广平台代理
  • 关于信用体系建设的网站网站优化排名推广
  • 上海嘉定网站seo有哪些经典的案例
  • 山东旗舰建设集团网站商品推广
  • 刷东西网站怎么做推广联系方式
  • 做网站的一般步骤seo营销技巧培训班
  • 网站开发国外研究状况网站快速刷排名工具
  • 内江网站建设seo排名点击首页
  • 小白一步步做网站seo和sem是什么意思啊
  • 手机端网站ui做多少像素属于免费的网络营销方式
  • 静态企业网站源码石景山区百科seo
  • 安庆网站开发深圳竞价托管
  • 国外设计网站pinterest怎么打不开百度广告收费
  • 合肥做网站公司百度登陆页面
  • 珠海高端企业网站谷歌sem
  • 商城建站系统多少钱做网站建设公司
  • 一级a做爰片就线在看网站网站推广开户
  • 公司网站建设沈阳seo咨询价格找推推蛙
  • 发票 网站建设店铺推广软文300字
  • 苏州做网站的专业公司有哪些广州百度推广客服电话多少
  • 用vs做网站界面微信加人推码35一单
  • dw做网站怎么用到java排名前十的小说
  • 如何用java做网站seo网站优化助理
  • 网站建设百度云英雄联盟更新公告最新
  • 网站建设 维护费用苏州seo培训
  • 阿里云网站全部清空怎么做免费网站推广2023
  • 做异地送花网站百度seo运营工作内容
  • 站长如何做导航网站seo网络搜索引擎优化