C#下载页面返回旧页面

时间:2015-09-01 11:30:23

标签: c# html-agility-pack system.net

我有问题,我写了一种方法来获取捷克电台的当前歌曲。他们没有API所以我必须通过html agility.dll从html获取歌曲 问题是即使歌曲标题在页面上更改我的方法下载旧页面,通常我必须等待20秒并让我的应用程序关闭,然后它的工作原理。 我认为一些缓存问题,但我无法解决它。 尝试过:DownloadString方法也没有刷新。

public static string[] GetEV2Songs()
{
     List<string> songy = new List<string>();
     string urlAddress = "http://www.evropa2.cz/";
     string data = "";
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);

     HttpWebResponse response = (HttpWebResponse)request.GetResponse();

     if (response.StatusCode == HttpStatusCode.OK)
     {
         Stream receiveStream = response.GetResponseStream();
         StreamReader readStream = null;

         if (response.CharacterSet == null)
             readStream = new StreamReader(receiveStream);
         else
             readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));

         data = readStream.ReadToEnd();

         response.Close();
         readStream.Close();
    }

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(data);
    string temp = "";

    foreach (var node in doc.DocumentNode.SelectNodes("//body//h2"))
    {
            if (node.InnerText.Contains("&ndash"))
            {
                temp = node.InnerText.Replace("&ndash;", "-");
                songy.Add(temp);

            }
     }

     return songy.ToArray();
 }

1 个答案:

答案 0 :(得分:1)

听起来像是一个缓存问题。尝试用类似的东西替换第4行:

string urlAddress = "http://www.evropa2.cz/?_=" + System.Guid.NewGuid().ToString();