java下载mms:开头的视频

java下载mms:开头的视频,第1张

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

import java.io.BufferedInputStream

import java.io.BufferedReader

import java.io.FileOutputStream

import java.io.InputStreamReader

import java.net.HttpURLConnection

import java.net.URL

import java.net.URLConnection

public class URLConnectionDemo {

public static void main(String[] args) throws Exception{

URL url = new URL("<a href="http://v.youku.com/v_show/id_XNzI0OTU2MzUy.html"" target="_blank">http://v.youku.com/v_show/id_XNzI0OTU2MzUy.html"</a>)

URLConnection uc = url.openConnection()

BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()))

String str= null

String xz = ""

while((str=br.readLine())!=null){

if(str.indexOf(".swf")!=-1){

try{

xz = str.substring(str.lastIndexOf("http"),str.indexOf(".swf") + 4)

}catch(Exception e){

}

}

}

System.out.println("下载地址为:" + xz)

getDondow(xz,"F:\\xx.swf")

}

//下载视频方法

private static void getDondow(String url,String pathName)throws Exception{

URL ul = new URL(url)

HttpURLConnection conn = (HttpURLConnection) ul.openConnection()

BufferedInputStream bi = new BufferedInputStream(conn.getInputStream())

FileOutputStream bs = new FileOutputStream(pathName)

System.out.println("文件大约:"+(conn.getContentLength()/1024)+"K")

byte[] by = new byte[1024]

int len = 0

while((len=bi.read(by))!=-1){

bs.write(by,0,len)

}

bs.close()

bi.close()

}

}

/*这是个下载图片的爬虫给你参考一下*/

import java.io.File

import java.net.URL

import java.net.URLConnection

import java.nio.file.Files

import java.nio.file.Paths

import java.util.Scanner

import java.util.UUID

import java.util.regex.Matcher

import java.util.regex.Pattern

public class DownMM {

public static void main(String[] args) throws Exception {

//out为输出的路径,注意要以\\结尾

String out = "D:\\JSP\\pic\\java\\"

try{

File f = new File(out)

if(! f.exists()) {

f.mkdirs()

}

}catch(Exception e){

System.out.println("no")

}

String url = "http://www.mzitu.com/share/comment-page-"

Pattern reg = Pattern.compile("<img src=\"(.*?)\"")

for(int j=0, i=1i<=10i++){

URL uu = new URL(url+i)

URLConnection conn = uu.openConnection()

conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3WOW64Trident/7.0rv:11.0) like Gecko")

Scanner sc = new Scanner(conn.getInputStream())

Matcher m = reg.matcher(sc.useDelimiter("\\A").next())

while(m.find()){

Files.copy(new URL(m.group(1)).openStream(), Paths.get(out + UUID.randomUUID() + ".jpg"))

System.out.println("已下载:"+j++)

}

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11818015.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存