The process starts with a simple process, that is, simulating a browser to access the address of the Baidu disk and then extracting the actual address. The core function is this:
[Csharp]
// Baidu disk address http://pan.baidu.com/share/link? Consumer id = 112694 & uk = 455690558
Private string ConvertBaiduPan_Thunder (string strBaiduPan)
{
If (strBaiduPan = null)
{
Return null;
}
String strThunder = null;
// Access Baidu disk address
String strBaiduPanWebPage = MyHttp. GetHtml (strBaiduPan );
If (strBaiduPanWebPage = "")
{
MessageBox. Show ("access address failed! "+ StrBaiduPan );
Goto End;
}
// Retrieve <a class = "dbtn cancel B-fr" href = "http://www.baidupcs.com/file/8d29f2f27f5939fabc7260e23f4739dd? Fid = 455690558-250528-2069072566 & time = 1358472203 & sign = FDTA-DCb740ccc5511e5e8fedcff06b081203-E0ZjQ1awurzhDkjhV5c % 2BtTN05nA % 3D & expires = 8 h & sh = 1 & response-cache-control = private "id =" downFileButtom "> <B> download (2.44 MB) </B> </a>
// Match the regular expression <a class = "dbtn cancel B-fr" href = "http ://.*? "> *. Id =" downFileButtom "> <B>
Regex r = new Regex ("<a class = \" dbtn cancel B-fr \ "href = \" http ://.*? \ "> *. Id = \" downFileButtom \ "> <B> ");
// Start matching
Match m = r. Match (strBaiduPanWebPage );
String strLink = null;
While (m. Success)
{
StrLink = m. Groups [0]. Value;
// Extract the value of href http://www.baidupcs.com/file/8d29f2f27f5939fabc7260e23f4739dd? Fid = 455690558-250528-2069072566 & time = 1358470090 & sign = FDTA-DCb740ccc5511e5e8fedcff06b081203-OiOC3pLc236790OikWTlSsTHWjc % 3D & expires = 8 h & sh = 1 & response-cache-control = private "id =" downFileButtom"
Regex r2 = new Regex ("http .*\"");
// Start matching
Match m2 = r2.Match (strLink );
While (m2.Success)
{
StrLink = m2.Groups [0]. Value;
StrLink = strLink. Replace ("&","&");
// Contains double quotation marks "id =" downFileButtom"
StrLink = strLink. Replace ("\"","");
StrLink = strLink. Replace ("id = downFileButtom ","");
M2 = m2.NextMatch ();
}
// Start the next match from the end of the last match
M = m. NextMatch ();
StrThunder = strLink;
}
End:
Return strThunder;
}
// Baidu disk address http://pan.baidu.com/share/link? Consumer id = 112694 & uk = 455690558
Private string ConvertBaiduPan_Thunder (string strBaiduPan)
{
If (strBaiduPan = null)
{
Return null;
}
String strThunder = null;
// Access Baidu disk address
String strBaiduPanWebPage = MyHttp. GetHtml (strBaiduPan );
If (strBaiduPanWebPage = "")
{
MessageBox. Show ("access address failed! "+ StrBaiduPan );
Goto End;
}
// Retrieve <a class = "dbtn cancel B-fr" href = "http://www.baidupcs.com/file/8d29f2f27f5939fabc7260e23f4739dd? Fid = 455690558-250528-2069072566 & time = 1358472203 & sign = FDTA-DCb740ccc5511e5e8fedcff06b081203-E0ZjQ1awurzhDkjhV5c % 2BtTN05nA % 3D & expires = 8 h & sh = 1 & response-cache-control = private "id =" downFileButtom "> <B> download (2.44 MB) </B> </a>
// Match the regular expression <a class = "dbtn cancel B-fr" href = "http ://.*? "> *. Id =" downFileButtom "> <B>
Regex r = new Regex ("<a class = \" dbtn cancel B-fr \ "href = \" http ://.*? \ "> *. Id = \" downFileButtom \ "> <B> ");
// Start matching
Match m = r. Match (strBaiduPanWebPage );
String strLink = null;
While (m. Success)
{
StrLink = m. Groups [0]. Value;
// Extract the value of href http://www.baidupcs.com/file/8d29f2f27f5939fabc7260e23f4739dd? Fid = 455690558-250528-2069072566 & time = 1358470090 & sign = FDTA-DCb740ccc5511e5e8fedcff06b081203-OiOC3pLc236790OikWTlSsTHWjc % 3D & expires = 8 h & sh = 1 & response-cache-control = private "id =" downFileButtom"
Regex r2 = new Regex ("http .*\"");
// Start matching
Match m2 = r2.Match (strLink );
While (m2.Success)
{
StrLink = m2.Groups [0]. Value;
StrLink = strLink. Replace ("&","&");
// Contains double quotation marks "id =" downFileButtom"
StrLink = strLink. Replace ("\"","");
StrLink = strLink. Replace ("id = downFileButtom ","");
M2 = m2.NextMatch ();
}
// Start the next match from the end of the last match
M = m. NextMatch ();
StrThunder = strLink;
}
End:
Return strThunder;
}
The above function is used to retrieve the file address from the Baidu Network Disk. It's easy to match web page capture and text, right. If you have any questions, read the source code or leave a message for me. As a Tom, he is happy to communicate with many cainiao.