需要将&tp=webp&wxfrom=5去掉,既可以在任何地方显示,也可以下载了

http://mmbiz.qpic.cn/mmbiz_jpg/bf8pC39RBhGFOH1ib9AcqC9k43d5yvcCJMspwk2Eam49QliaymWy1P590MLKgjPcYffXQNWhhTPicKk1unQIGQ2XQ/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1
http://mmbiz.qpic.cn/mmbiz_jpg/bf8pC39RBhGFOH1ib9AcqC9k43d5yvcCJMspwk2Eam49QliaymWy1P590MLKgjPcYffXQNWhhTPicKk1unQIGQ2XQ/640?wx_fmt=jpeg&wx_lazy=1

java 下载微信公众号里面的图片

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class GetWexinImage { /**
* 下载微信公众号里的图片
* @param request
* @param response
*/
@RequestMapping("/test/a")
public void a(HttpServletRequest request, HttpServletResponse response) {
String url = "http://mmbiz.qpic.cn/mmbiz_jpg/bf8pC39RBhGFOH1ib9AcqC9k43d5yvcCJt44g7k8DDGyOlXI7Qyw2GGT6NWhWBjPzhWPLnp9zZJTDY3D167kdMA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1";
InputStream fis = null;
OutputStream os = null;
try {
URL getUrl = new URL(url);
URLConnection connection = getUrl.openConnection();
connection.setRequestProperty("Referer", "");
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36");
connection.setDoOutput(true);
fis = connection.getInputStream();
os = response.getOutputStream();
int count = 0;
byte[] buffer = new byte[1024 * 1024];
while ((count = fis.read(buffer)) != -1) {
os.write(buffer, 0, count);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null){
try {
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
response.setContentType("image/*");
} }

java 下载微信公众号里面的图片,保存到本地,需要将&tp=webp&wxfrom=5去掉,既可以在任何地方显示,也可以下载了

 /**
* 下载微信公众号里的图片
* @param request
* @param response
*/
@RequestMapping("/test/b")
public void b(HttpServletRequest request, HttpServletResponse response) {
String url = "http://mmbiz.qpic.cn/mmbiz_jpg/bf8pC39RBhGFOH1ib9AcqC9k43d5yvcCJt44g7k8DDGyOlXI7Qyw2GGT6NWhWBjPzhWPLnp9zZJTDY3D167kdMA/640?wx_fmt=jpeg&wx_lazy=1";
InputStream fis = null;
FileOutputStream fos = null;
try {
URL getUrl = new URL(url);
URLConnection connection = getUrl.openConnection();
connection.setRequestProperty("Referer", "");
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36");
connection.setDoOutput(true);
fis = connection.getInputStream();
File file = new File("D://test/a.jpg");
fos = new FileOutputStream(file);
int count = 0;
byte[] buffer = new byte[1024 * 1024];
while ((count = fis.read(buffer)) != -1) {
fos.write(buffer, 0, count);
} } catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null){
try {
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null){
try {
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

java 根据url地址生成html页面文件

import java.io.File;
import java.io.FileOutputStream;
public class GenerateIndexPage { protected static String defaultToFile = "d://test.html";
protected static String defaultFromFile = "https://mp.weixin.qq.com/s/OYJzYiQRepc8yfrGReITDA"; public static void main(String[] args) throws Exception {
genHtml(defaultFromFile);
} public static String genHtml(String fromFile) throws Exception {
String result = "";
java.net.URL url = new java.net.URL(fromFile);
java.net.HttpURLConnection conn =(java.net.HttpURLConnection) url.openConnection();
try{
if (conn.getResponseCode() == 200) { java.io.InputStream is = (java.io.InputStream) conn.getContent();
try{
FileOutputStream baos = new FileOutputStream(new File(defaultToFile));
int buffer = 1024;
byte[] b = new byte[buffer];
int n = 0;
while ((n = is.read(b, 0, buffer)) > 0) {
baos.write(b, 0, n);
}
//String s = new String(baos.toByteArray(), WEATHER_HTML_CHARSET);
is.close();
baos.close();
result = "生成成功";
}catch(Exception e){
result="写文件过程出错,取消生成。";
}
}else{
result="获得链接过程出错,取消生成。";
}
}catch(Exception e){
e.printStackTrace();
result="获得内容过程出错,取消生成。";
}
return result;
}

java根据url地址,获取页面内容

public class GetHtml {

    public static void main(String[] args) throws Exception {
getHtml();
}
public static String getHtml() throws Exception {
//System.setProperty("http.proxyHost", "isaserver");System.setProperty("http.proxyPort", "80");
java.net.URL url = new java.net.URL("https://mp.weixin.qq.com/s/OYJzYiQRepc8yfrGReITDA");
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
if (conn.getResponseCode() == 200) {
java.io.InputStream is = (java.io.InputStream) conn.getContent();
java.io.ByteArrayOutputStream baos =
new java.io.ByteArrayOutputStream(); int buffer = 1024;
byte[] b = new byte[buffer];
int n = 0;
while ((n = is.read(b, 0, buffer)) > 0) {
baos.write(b, 0, n);
}
String s = new String(baos.toByteArray(), "UTF-8");
is.close();
baos.close();
System.out.println(s);
return s;
}
return "";
}
}

根据url下载图片和页面的更多相关文章

  1. C++根据图片url下载图片

    需要使用到URLDownloadToFile()函数,该函数在头文件<urlmon.h>中声明. URLDownloadToFile()函数的定义如下: HRESULT URLDownlo ...

  2. 从url下载图片--java与python实现方式比较

    从url下载图片--java与python实现方式比较 博客分类: 技术笔记小点滴 javapython图片下载  一.java的实现方式 首先读取图片 //方式一:直接根据url读取图片 priva ...

  3. JAVA 通过url下载图片保存到本地

    //java 通过url下载图片保存到本地 public static void download(String urlString, int i) throws Exception { // 构造U ...

  4. QT通过url下载图片到本地

    /* strUrl:下载图片时需要的url strFilePath:下载图片的位置(/home/XXX/YYY.png) */ void ThorPromote::downloadFileFromUr ...

  5. 根据URL地址获取对应的HTML,根据对应的URL下载图片

    核心代码(获取HTML): #region 根据URL地址获取信息GET public static String GetResult(string url) { return GetResult(u ...

  6. js 根据url 下载图片

    downloadIamge(imgsrc, name) {//下载图片地址和图片名 let image = new Image(); // 解决跨域 Canvas 污染问题 image.setAttr ...

  7. js 根据url 下载图片 前端js 实现文件下载

    1.H5 download属性 function downFile(content, filename) { // 创建隐藏的可下载链接 var eleLink = document.createEl ...

  8. 根据URL下载图片到本地

    /// <summary> /// 下载图片 /// </summary> /// <param name="picUrl">图片Http地址& ...

  9. python实现通过URL下载图片到本地服务器

    import os import urllib.request image_url = 'http://img.jingtuitui.com/759fa20190115144450401.jpg' f ...

随机推荐

  1. POJ 2513 Colored Sticks(Tire+欧拉回(通)路判断)

    题目链接:http://poj.org/problem?id=2513 题目大意:你有好多根棍子,这些棍子的两端分都别涂了一种颜色.请问你手中的这些棍子能否互相拼接,从而形成一条直线呢? 两根棍子只有 ...

  2. hdu 5894(组合数取模)

    hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

  3. HNOI 2014

    D1T1:画框 frame 题意:给你两个n阶正整数方阵,请你求最大的\( \sum_{i = 1}^{n} A_{i, p_i}\times \sum_{i = 1}^{n} B_{i, p_i}  ...

  4. c++ primer 3 标准库类型

    3.1 命名空间的using声明 using声明是对某个命名空间做引入.主要作用是简化代码编写. 比如用cout的三种方式: using namespace std; using std::cout; ...

  5. 从函数调用的角度,探讨JavaScript中this的用法

    js函数调用方式大概可分为:函数调用,构造器调用,call或apply,方法调用四种方式.下面结合一些基础概念和实测代码,从函数调用的角度,探讨JavaScript中this的用法. 1. new对函 ...

  6. Python爬虫-正则表达式基础

    import re #常规匹配 content = 'Hello 1234567 World_This is a Regex Demo' #result = re.match('^Hello\s\d\ ...

  7. 《Android虚拟机》----虚拟机概述

    No1: 虚拟机是指通过软件模拟的具有完整硬件系统功能的.运行在一个完全隔离的环境中的完整计算机系统. No2: Java虚拟机由如下五个部分组成:一组指令集.一组寄存器.一个栈.一个无用单元收集堆. ...

  8. 解释Crypto模块怎么就这么"皮"?No module named "Crypto"

    https://www.cnblogs.com/fawaikuangtu123/p/9761943.html python版本:python3.6,系统:win7 1.pip install cryp ...

  9. 【BZOJ 4035】 4035: [HAOI2015]数组游戏 (博弈)

    4035: [HAOI2015]数组游戏 Time Limit: 15 Sec  Memory Limit: 32 MBSubmit: 181  Solved: 89 Description 有一个长 ...

  10. android studio 汉化 美化 个性化 修改 安卓工作室 2.3.3 最新版

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 先看一下效果. 建议全屏看图,或者新标签看图.