分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程
HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成
HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子
| 寻找iOS上架技术,要求简单,内容不限,长期合作,价格高,中介勿扰!有意者联系邮箱:make101love@126.com QQ:1060088990 |
|
苏飞大大超赞~ |
clrscr 发表于 2019-8-2 00:20 哈哈,厉害,应该是成功了,我也试好了,原来是他网站跳转了多次,跟着手动跳就好了,谢谢哈~ ![]() |
![]() |
可能是成功了? [C#] 纯文本查看 复制代码 private void GetCode()
{
//获取Cookie
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://9714035371-ccgj.qq168.ws/ssid1?url=/js/jquery.js",
Method = "GET",
Referer = "https://9714035371-ccgj.qq168.ws/login",
ProxyIp = "127.0.0.1:8888",
};
HttpResult result = http.GetHtml(item);
string JSCookie = result.Cookie;
//获取验证码图片
item = new HttpItem()
{
URL = "https://9714035371-ccgj.qq168.ws/code?_=" + GetTimeC(),
Method = "GET",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
Referer = "https://9714035371-ccgj.qq168.ws/login",
ResultType = ResultType.Byte,
ProxyIp = "127.0.0.1:8888",
};
result = http.GetHtml(item);
imgCode.Source = LoadImage(result.ResultByte);
string ImgCodeCode = result.Cookie;
//获取Cookie
item = new HttpItem()
{
URL = "https://9714035371-ccgj.qq168.ws/ssid1?url=/default/js/qrcode.min.js",
Method = "GET",
Referer = "https://9714035371-ccgj.qq168.ws/login",
Cookie = JSCookie,
ProxyIp = "127.0.0.1:8888",
};
result = http.GetHtml(item);
string JSCookie2 = result.Cookie;
MyCookie = ImgCodeCode + ";" + JSCookie2;
}
private string OneKeyLogin()
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "https://9714035371-ccgj.qq168.ws/login",
Method = "POST",
Referer = "https://9714035371-ccgj.qq168.ws/login",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
ContentType = "application/x-www-form-urlencoded",
KeepAlive = true,
Cookie = MyCookie,
ProxyIp = "127.0.0.1:8888",
Postdata = "type=1&account=" + user + "&password=" + pass + "&code=" + txtCode.Text,
};
HttpResult result = http.GetHtml(item);
string html = result.Html;
string NewUrl = result.RedirectUrl;
item = new HttpItem()
{
URL = NewUrl,
Method = "GET",
Referer = "https://9714035371-ccgj.qq168.ws/login",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
Cookie = MyCookie,
};
result = http.GetHtml(item);
string Cookie = result.Cookie;
Cookie = HttpHelper.GetSmallCookie(Cookie);
item = new HttpItem()
{
URL = "https://9714035371-ccgj.qq168.ws/member/agreement",
Method = "GET",
Referer = "https://9714035371-ccgj.qq168.ws/login",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
Cookie = Cookie,
};
result = http.GetHtml(item);
html = result.Html;
Cookie = Cookie + MyCookie;
item = new HttpItem()
{
URL = "https://9714035371-ccgj.qq168.ws/member/index",
Method = "GET",
Referer = "https://9714035371-ccgj.qq168.ws/member/agreement",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
Cookie = Cookie,
};
result = http.GetHtml(item);
html = result.Html;
return html;
}
private System.Drawing.Image byteArrayToImage(byte[] Bytes)
{
MemoryStream ms = new MemoryStream(Bytes);
return System.Drawing.Bitmap.FromStream(ms, true);
}
BitmapSource LoadImage(Byte[] imageData)
{
using (MemoryStream ms = new MemoryStream(imageData))
{
var decoder = BitmapDecoder.Create(ms,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
return decoder.Frames[0];
}
}
} |
|
问题解决了,是网站本身设计得厉害,会多次302,我一直手动追踪请求到第5次就能跳转到用户主页了,重复执行5次以下: [C#] 纯文本查看 复制代码 //获取302跳转URl string redirectUrl = _httpResult.RedirectUrl;
_httpItem = new HttpItem()
{
URL = redirectUrl,//URL 必需项
Accept = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
Method = "GET",//URL 可选项 默认为Get
Cookie = _cookie,
Referer = "https://9714035371-ccgj.qq168.ws/login",
};
_httpItem.Header.Add("Accept-Language", "zh-cn");
//请求的返回值对象
_httpResult = _http.GetHtml(_httpItem);
//获取请请求的Html
string html = _httpResult.Html;感谢感谢~ |
站长苏飞 发表于 2019-8-1 18:16 不太会,能否在代码上指导一下,万分感谢 ![]() |
| 把Cookie的path=/和过期时间去掉 |
clrscr 发表于 2019-8-1 09:42 我私信您了,请看一下论坛消息 |