Mit HtmlAgilityPack und c # 4.0 können Sie feststellen, ob die Seite umgeleitet wird oder nicht. Ich verwende diese Methode, um die Seite zu laden.
HtmlDocument hdMyDoc = hwWeb.Load(srPageUrl);
Und Beispiel Umleitungsergebnis nehme ich an
Zurückgegebenes inneres HTML
<meta http-equıv="refresh" content="0;URL=http://www.pratikev.com/fractalv33/pratikEv/pages/home.jsp">
c # 4.0
In diesem Fall analysieren Sie den HTML-Code am besten.
var page = "...";
var doc = new HtmlDocument();
doc.Load(page);
var root = doc.DocumentNode;
var select = root.SelectNodes("//meta[contains(@content, 'URL')]");
try
{
Console.WriteLine("has redirect..");
Console.WriteLine(select[0].Attributes["content"].Value.Split('=')[1]);
}
catch
{
Console.WriteLine("have not redirect using HTML");
}
Angenommen, das Dokument ist relativ wohlgeformt, könnte man wohl so etwas machen:
static string GetMetaRefreshUrl(string sourceUrl)
{
var web = new HtmlWeb();
var doc = web.Load(sourceUrl);
var xpath = "//meta[@http-equiv='refresh' and contains(@content, 'URL')]";
var refresh = doc.DocumentNode.SelectSingleNode(xpath);
if (refresh == null)
return null;
var content = refresh.Attributes["content"].Value;
return Regex.Match(content, @"\s*URL\s*=\s*([^ ;]+)").Groups[1].Value.Trim();
}