[C # source code] Baidu online storage address batch conversion tool

Source: Internet
Author: User

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.

 

 

 

 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.