我正在编写一个连接到此site的Java程序,然后模拟将URL传递到文本字段,点击转换按钮,然后获取生成的下载URL。我检查了网站的网络流量,下载的URL在标题选项卡下有以下数据:
按下载按钮后,我看到了......
**General:**
Remote Address:64.233.171.121:80
Request URL:http://www.youtube-mp3.org/a/itemInfo/?video_id=KMU0tzLwhbE&ac=www&t=grp&r=1439422557443&s=63079
Request Method:GET
Status Code:200 OK
**Response Headers:**
view source
Cache-Control:no-cache
Content-Encoding:gzip
Content-Length:249
Content-Type:text/html; charset=utf-8
Date:Wed, 12 Aug 2015 23:35:57 GMT
Server:Google Frontend
Vary:Accept-Encoding
**Request Headers:**
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Accept-Location:*
Cache-Control:no-cache
Connection:keep-alive
Cookie:_ga=GA1.2.1715601918.1425946204; ux=cce7b6d7-c6b9-11e4-8ef7- 5557045ab030|0|0|1439422547|1439854547|3536a31fad07ba73ecc1e4ba4b3cf3d6; __ utmt=1; __utma=120311424.1715601918.1425946204.1439420885.1439421591.16; __utmb=120311424.3.10.1439421591; __utmc=120311424; __utmz=120311424.1439421591.16.16.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
Host:www.youtube-mp3.org
Referer:http://www.youtube-mp3.org/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36
**Query String Parameters:**
view source
view URL encoded
video_id:KMU0tzLwhbE
ac:www
t:grp
r:1439422557443
s:63079
在inspect元素的“Response”选项卡下(在Network下)显示:
info = {"status": "serving", "h2": "c0c0d91ef9ca62df13a43f71c6ad8ea3", "image": "http://i.ytimg.com/vi/KMU0tzLwhbE/default.jpg", "progress_speed": "", "ads": "", "title": "Developers", "h": "fa5ef79cbdee0bb33da3348818b26715", "px": "", "ts_create": "1439422557", "length": "3", "r": "NzMuMjE1LjIxMC4w", "pf": "", "progress": ""};
现在,我正在尝试获取这些数据,然后我将在获取必要参数后解析为下载URL。但是,我不确定如何访问此信息。我创建了一个像这样的Jsoup GET请求:
Connection.Response res = null;
Document doc = null;
String id;
String vidID;
String downloadURL;
Scanner input = new Scanner(System.in);
System.out.print("URL: ");
id = input.nextLine();
vidID = id.substring(id.length()-11,id.length());
try{
res = Jsoup.connect("http://www.youtube-mp3.org/")
.referrer("http://www.youtube-mp3.org/")
.header("Accept","*/*")
.data("video_id",vidID)
.method(Connection.Method.GET)
.execute();
//not sure how to proceed
}
但这对我不起作用。我能够从用户的输入中获得必要的video_id参数,这样就可以了。但是,我无法找到“请求URL:”参数列出的其余必要参数。如何构建连接到站点并传递输入的URL的请求?然后,我将如何获取inspect元素中的Network / Reponse选项卡下列出的信息?
感谢您的任何建议
编辑:
因此请求URL看起来像这样:(注意:这是在响应选项卡下面带有下载URL信息的页面的请求,因此我首先需要对以下URL发出请求)
http://www.youtube-mp3.org/a/itemInfo/?video_id=KMU0tzLwhbE&ac=www&t=grp&r=1439422557443&s=63079
我知道video_id,我假设“ac”值始终是www并且“t”值是grp,但是,“r”和“s”参数似乎是针对每个视频生成的,我现在还不知道怎么......
更新:好吧,经过进一步的探索,看起来我需要做两件事来完成我需要的东西......
以下列形式向网址发出GET请求:
http://www.youtube-mp3.org/a/itemInfo/?video_id=KMU0tzLwhbE&ac=www&t=grp&r=1439425642030&s=5534
传入“item”(没问题),“el”(没问题),“bf”(没问题),“r”(需要获取)和“s”(需要获取)的值
然后这样做......
对预先下载的URL进行另一个GET请求,其格式如下:
http://www.youtube-mp3.org/a/itemInfo/?video_id=KMU0tzLwhbE&ac=www&t=grp&r=1439425642030&s=5534
然后