java吧 关注:1,255,236贴子:12,744,097
  • 15回复贴,共1

优酷视频缩略图

只看楼主收藏回复

public class VideoTest {
public static void main(String[] args) throws Exception{
String pic = getElementAttrById("s_sina", "href");
int local = pic.indexOf("pic=");
pic = pic.substring(local+4);
System.out.println("视频缩略图:"+pic);
}
private static String getElementAttrById(String id, String attrName)throws Exception{
Document doc = getURLContent();
Element et = doc.getElementById(id);
String attrValue = et.attr(attrName);
return attrValue;
}
private static Document getURLContent() throws MalformedURLException, IOException, UnsupportedEncodingException {
Document doc = Jsoup.connect("http://v.youku.com/v_show/id_XNTU1MDkyNDYw.html?f=19264429&ev=2")
.data("query", "Java")
.userAgent("Mozilla")
.cookie("auth", "token")
.timeout(3000)
.post();
return doc;
}
}
获取到的是个地址 但我需要的是这张图片 如何获取到图片呢?
求指导!!!!


1楼2013-05-11 12:11回复
    不懂帮顶


    IP属地:广东2楼2013-05-11 12:23
    收起回复
      来个大神啊?


      3楼2013-05-11 12:45
      回复
        不懂帮顶


        IP属地:湖南4楼2013-05-11 13:14
        收起回复
          。。。。。。。。。。。。。。


          5楼2013-05-11 15:35
          回复
            既然能获得地址,把地址包装成URL然后用URL.openConnection打开连接再读取就好了
            另外……你总不会是想把图片打印到控制台吧……


            IP属地:广西7楼2013-05-11 19:52
            收起回复
              返回的那个页面包含有缩略图的地址,在html里搜索到那个结点就可以提取出来了。html解析没怎么尝试过,不知道能不能用SAX……反正只要能拿到地址一切都好办


              IP属地:广西10楼2013-05-11 22:33
              收起回复
                找到方法了嗎?


                11楼2017-05-26 22:43
                回复