avatar
c*t
1
http://www.linqpad.net/
It's not as heavy as VS; but very handy to test out code snippets. For an
exmple download music from wenxuecity.com. Once you figured out the
playListXml (either view source or sniff), a few lines code as follows run
great in LinqPad:
void Main()
{
string playListUrl = @"http://space.wenxuecity.com/media/1292261551.xml";

using(WebClient wc = new WebClient())
{
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE
8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .
NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)"
);
string xmlContent = wc.DownloadString(playListUrl);
XDocument doc = XDocument.Parse(xmlContent);

foreach(var s in doc.Descendants("song"))
{
string fileName = s.Attribute("name").Value;
string uri = s.Attribute("file").Value;

Console.WriteLine("Downloading {0}", fileName);

if(uri.EndsWith(".mp3") && !fileName.EndsWith(".mp3"
))
fileName = string.Concat(fileName, ".mp3");
fileName = string.Concat(@"C:\Temp\music\", fileName
);
if( !Directory.Exists(@"C:\Temp\music") ) Directory.
CreateDirectory(@"C:\Temp\music");

wc.Headers.Clear();
wc.Headers.Add("User-Agent", "Windows-Media-Player/
11.0.5721.5145");

wc.DownloadFile(uri, fileName);

}
Console.WriteLine("All done");
}
}
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。