概述
应朋友要求, 需要下载一些微信购买的课程视频资料, 话不多说, 开干.
1. 获取微信访问头
*首先在浏览器设置微信访问头, 并使用账号密码进行登陆*
- chrome - 更多工具 - 开发者工具 - 右上角 - more tools - Network Conditions - 选择手机访问头
- 输入网址并登录账号密码 - 获取访问头
2. 设置微信访问头
public Document getDoc(String url) throws Exception {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("User-Agent", "MMozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12A365 MicroMessenger/5.4.1 NetType/WIFI");
httpGet.setHeader("Referer","链接");
httpGet.setHeader("Host", "host 链接");
httpGet.setHeader("Cookie", " 账号密码cookie ");
httpGet.setHeader("Accept-Encoding", "gzip, deflate");
httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
HttpResponse response = httpClient.execute(httpGet);
String contents = EntityUtils.toString(response.getEntity(), "utf-8");// utf-8
Document document = Jsoup.parse(contents);
return document;
}
3. 获取视频页网址
private List<String> getUrls(Document doc) {
// TODO Auto-generated method stub
List<String> list = new ArrayList<String>();
Elements elements = doc.select("body > div.wapbody > div.tbox").select("a");
for (Element element : elements) {
String url = "链接头" + element.attr("href");
System.out.println(url);
list.add(url);
}
return list;
}
4. 获取bat 脚本下载连接 ( 给电脑盲的傻瓜操作 )
String getVideo(String url) throws Exception {
Document doc = getDoc(url);
String docString = doc.toString();
String name = doc.select("body > div.wapbody > div.tbox > div.teaching-title > h1").text();
int fromIndex = docString.indexOf("http://");
int toIndex = docString.indexOf(".mp4");
String nameString = name.replaceAll(")", "").replaceAll("(", "").replaceAll(":", "");
String urlString = docString.substring(fromIndex, toIndex+4);
return "curl -# -o "+nameString+" "+urlString;
}
5. 打印脚本下载连接并另存为bat脚本, 就OK了
总结:
感觉对于 Jsoup 的 selector 还不太熟悉, 需要再好好看一下.
最后
以上就是清脆毛衣为你收集整理的下载微信网页内视频的全部内容,希望文章能够帮你解决下载微信网页内视频所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复