分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程
HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成
HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子
sugaew 发表于 2018-9-28 14:19 不客气,为人民服务! |
| 看了楼主的文章,解决了我的问题,谢谢 |
| 我只是路过打酱油的。 |
|
GetImage 函数里返回值调用了一次(GetHtml(item).ResultByte)导致多获取了一次验证码,看来验证码图片获取是不能用 Image img = http.GetImage(item); pictureBox1.Image = img; 这样的方式还调用的。 直接用其调用的ByteToImage函数里的代码: MemoryStream ms = new MemoryStream(b); return Bitmap.FromStream(ms, true); |
zncliving 发表于 2018-7-29 20:45 你是我的曙光! 我竟然没怀疑是这个验证码图片获取函数的问题,这个函数肯定是又请求了一次,导致获取了新的Cookie |
| 又一天过去了,无进展。 |
|
[C#] 纯文本查看 复制代码 private void GetVerCode()
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.510376.com/login.php",
Accept = "text/html, application/xhtml+xml, */*",
Method = "get",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = Cookie,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Referer = "http://www.510376.com/login.php",//来源URL 可选项
ResultType = ResultType.String,//返回数据类型,是Byte还是String
};
HttpResult result = http.GetHtml(item);
Cookie_A = result.Cookie;
txtHtml.Text = " 第一次访问时的Cookie:\n" + Cookie_A;
item = new HttpItem()
{
URL = "http://www.510376.com/tools/regcode.php?verify=08login&t=",
Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5",
Method = "get",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = Cookie_A,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Referer = "http://www.510376.com/login.php",//来源URL 可选项
ResultType = ResultType.Byte,//返回数据类型,是Byte还是String
};
//*********************************************修改的地方
//Image img = http.GetImage(item);
//pictureBox1.Image = img;
result = http.GetHtml(item);
MemoryStream ms = new MemoryStream(result.ResultByte);
pictureBox1.Image = Bitmap.FromStream(ms, true);
Cookie_A = result.Cookie.Replace("path=/,", "");
//*********************************************修改的地方
//Cookie_A = "6QC_Q5gqrT_upload=1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12; menubox1=menubox1; 6QC__08_hash=ae2fc5670e3b9b447624d0da87ad84bf;"+HttpHelper.GetSmallCookie(Cookie_A);
//获取请求的Cookie
txtHtml.Text = txtHtml.Text+"\n获取验证码时的Cookie:\n" + Cookie_A;
} |