我正在尝试通过使用以下代码段从给定的URL获取html代码。该网址包含一组产品。问题是它只为第一页获取正确的html。从第二页开始,它会提供相同的html第一页。我尝试了noCachePolicy,但是没有用。
class WClient : WebClient
{
protected override WebRequest GetWebRequest(Uri url)
{
var request = base.GetWebRequest(url) as HttpWebRequest;
request.AutomaticDecompression = DecompressionMethods.GZip;
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.CachePolicy = noCachePolicy;
return request;
}
}
var wc = new WClient();
wc.Encoding = Encoding.UTF8;
var result = wc.DownloadString(url[j]);