C#代码处理网页关于登录的code
Posted lopengye
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#代码处理网页关于登录的code相关的知识,希望对你有一定的参考价值。
作者:血饮狂龙
链接:https://www.zhihu.com/question/49452639/answer/117294801
来源:知乎
著作权归作者所有,转载请联系作者获得授权。
以上代码是再入一个普通网页的代码,采用get方法。下面再贴一段采用post方法的代码:
上面这段代码一般用于登录之类的提交请求的动作,比如登录。
下面提供一点儿干货:
想学习爬虫的童鞋,你们一定要看看这个网站:[C#HttpHelper]官方产品发布与源码下载 苏菲论坛,这个人把登录网页封装起来用,很方便哟。
你需要用到的工具有:httpwatch或者fiddler抓取网页数据。
win10的亲们,你们需要被特别照顾一下,因为那蛋疼的ie并不兼容httpwatch。firefox或者chrome目前对插件也管控特别严,因此你们需要用到以下组合:
firefox 35.0b8+Httpwatch9.4.17
链接:https://www.zhihu.com/question/49452639/answer/117294801
来源:知乎
著作权归作者所有,转载请联系作者获得授权。
private string gethtml(string url)
{
HttpItem item = new HttpItem()
{
URL = url,
Encoding = null,
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
KeepAlive = false,
UserAgent = userAgent,
Expect100Continue = true,
Header = new WebHeaderCollection()
{
{"Accept-Encoding","gzip, deflate"},
{"Accept-Language","zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"}
}
};
HttpResult result = http.GetHtml(item);
return result.Html;
}
private string postHtml(string url, string postData, string referer)
{
HttpItem item = new HttpItem()
{
URL = url,
Encoding = null,
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
KeepAlive = true,
ContentType = "application/x-www-form-urlencoded",
Referer = referer,
UserAgent = userAgent,
Expect100Continue = false,
Method = "POST",
Postdata = postData,
Header = new WebHeaderCollection()
{
{"Accept-Encoding","gzip, deflate"},
{"Accept-Language","zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"}
}
};
HttpResult result = http.GetHtml(item);
return result.Html;
}
下面提供一点儿干货:
想学习爬虫的童鞋,你们一定要看看这个网站:[C#HttpHelper]官方产品发布与源码下载 苏菲论坛,这个人把登录网页封装起来用,很方便哟。
你需要用到的工具有:httpwatch或者fiddler抓取网页数据。
win10的亲们,你们需要被特别照顾一下,因为那蛋疼的ie并不兼容httpwatch。firefox或者chrome目前对插件也管控特别严,因此你们需要用到以下组合:
firefox 35.0b8+Httpwatch9.4.17
以上是关于C#代码处理网页关于登录的code的主要内容,如果未能解决你的问题,请参考以下文章