[英]C# downloading page returns old page
我遇到了問題,我寫了一種方法來在捷克廣播電台獲取當前歌曲。 他們沒有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("–", "-");
songy.Add(temp);
}
}
return songy.ToArray();
}
聽起來像是一個緩存問題。 嘗試用類似以下內容替換第四行:
string urlAddress = "http://www.evropa2.cz/?_=" + System.Guid.NewGuid().ToString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.