我正在寻找从mediafire获得直接链接的方法。默认情况下,当用户访问下载链接时,他将看到一个下载页面,他必须等待下载处理,然后才会出现链接。
我用谷歌搜索并使用WebBrowser WB
找到了一个VB.NET 2008解决方案http://www.vbforums.com/showthread.php?t=556681
它工作得很好,但我已经厌倦了弹出窗口和加载速度。所以,我想知道这个问题是否有解决方案? (非WB解决方案^^)
非常感谢任何帮助。
答案 0 :(得分:3)
当我将正则表达式用于代码时,我将回发帖子,不确定这是否会起作用,因为我认为实际的链接是通过AJAX获得的。我还在玩这个。
讨论了AJAX问题:StackOverflow related question
基于评论中提供的php代码:
代码(警告此代码很丑陋,需要清理):
string sURL = "http://www.mediafire.com/?syzjuytmdkn";
HttpWebRequest wrGETURL = (HttpWebRequest)WebRequest.Create(sURL);
wrGETURL.CookieContainer = new CookieContainer();
wrGETURL.Referer = "http://www.mediafire.com";
wrGETURL.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
HttpWebResponse wrResponse = (HttpWebResponse)wrGETURL.GetResponse();
CookieCollection cookies = wrResponse.Cookies;
这里我们发送第一个请求&存储收到的cookie。接下来,我们要解析页面以找出第二个请求的键:
StreamReader objReader = new StreamReader(wrResponse.GetResponseStream());
string[] parameters = {};//will contain the parameters fetched
string html = objReader.ReadToEnd();
int cupos1 = html.IndexOf("cu(");
int cupos2 = html.IndexOf("')",cupos1);
string[] separators = { "','"};
parameters = html.Substring(cupos1 + 4, cupos2 - cupos1 - 4)
.Split(separators, StringSplitOptions.None);
获取包含编码下载网址的第二页:
string sURL2 = String.Format("http://www.mediafire.com/dynamic/download.php?qk={0}&pk={1}&r={2}",
parameters[0],parameters[1],parameters[2]);
HttpWebRequest wrGETURL2 = (HttpWebRequest)WebRequest.Create(sURL2);
wrGETURL2.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
wrGETURL2.Referer = "http://www.mediafire.com";
wrGETURL2.CookieContainer = new CookieContainer();
wrGETURL2.CookieContainer.Add(cookies);
wrResponse = (HttpWebResponse)wrGETURL2.GetResponse();
objReader = new StreamReader(wrResponse.GetResponseStream());
html = objReader.ReadToEnd();
这个html包含将生成下载URL的Javascript,在这里我们提取它,然后评估它&最后把它写到控制台:
int varpos1 = html.IndexOf("<script language=\"Javascript\">")+35;
//The variables are declared just before the 'function'
int varpos2 = html.IndexOf("function",varpos1);
string vardata = html.Substring(varpos1, varpos2 - varpos1);
int hrefpos1 = html.IndexOf("href=\\\"http://", varpos2)+6 ;
int hrefpos2 = html.IndexOf(">", hrefpos1);
string hrefdata = String.Format("var url = {0};", html.Substring(hrefpos1, hrefpos2 - hrefpos1-5));
object Result = EvalJScript(vardata + "\n" + hrefdata);
Console.WriteLine(Result.ToString());
这个东西对我有用,但需要重写,我也保留EvalJScript函数让你工作,因为我正在使用的那个(来自Evaluating JScript in c#)已被弃用
答案 1 :(得分:1)
Dim req As HttpWebRequest, res As HttpWebResponse
Dim cok As New CookieContainer, str As String, match As Match
req = WebRequest.Create("http://www.mediafire.com/?65d1dftjwml")
req.CookieContainer = cok
res = req.GetResponse
str = New StreamReader(res.GetResponseStream).ReadToEnd
match = Regex.Match(str, "cu\('(.+)','(.+)','(.+)'\);")
Dim qk As String = match.Groups(1).Value
Dim pk As String = match.Groups(2).Value
Dim r As String = match.Groups(3).Value
Dim t As String = "http://www.mediafire.com/dynamic/download.php?qk=" & qk & "&pk=" & pk & "&r=" & r & "&ukey=" & res.Cookies.Item("ukey").Value
req = WebRequest.Create(t)
res = req.GetResponse
txtcode.Text = New StreamReader(res.GetResponseStream).ReadToEnd
答案 2 :(得分:0)
我的原始答案的最后一段代码被切断了 - 它显示了评估jscript时的C#代码:
int varpos1 = html.IndexOf("<script language=\"Javascript\">")+35;
//The variables are declared just before the 'function'
int varpos2 = html.IndexOf("function",varpos1);
string vardata = html.Substring(varpos1, varpos2 - varpos1);
int hrefpos1 = html.IndexOf("href=\\\"http://", varpos2)+6 ;
int hrefpos2 = html.IndexOf(">", hrefpos1);
string hrefdata = String.Format("var url = {0};", html.Substring(hrefpos1, hrefpos2 - hrefpos1-5));
object Result = EvalJScript(vardata + "\n" + hrefdata);
Console.WriteLine(Result.ToString());