C#htmlagility包,捕获重定向 [英] C# htmlagility pack, capturing redirct

查看:81
本文介绍了C#htmlagility包,捕获重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这个真的很简单(我希望如此).我正在使用htmlagility pack进行网络爬网.那么,如果我输入url等任何东西,然后将我定向到一个新的URL,会发生什么情况,如何捕获该新的重定向URL?

HI all, this one is really simple (I hope). I'm using htmlagility pack to do my webcrawling. So what happens if I input url whatever, that then directs me to a new url, how do I capture that new redirected URL?

如果htmlagility pack没有办法,有人可以建议另一种方法吗?

If htmlagility pack doesnt have a way, can someone suggest another method?

推荐答案

创建HttpWebRequest时,可以将AllowAutoRedirect属性设置为true,它将自动跟随您进行的任何重定向.

When you create your HttpWebRequest you can set AllowAutoRedirect property to true and it will automatically follow any redirects you have.

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");  
myHttpWebRequest.MaximumAutomaticRedirections=1;
myHttpWebRequest.AllowAutoRedirect=true;
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse(); 

您可以在 msdn

这篇关于C#htmlagility包,捕获重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆