http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 6475|回复: 4

[求助] 浏览器打开可以直接下载,但是用httphelper抓取返回403

[复制链接]
发表于 2020-6-6 15:42:40 | 显示全部楼层 |阅读模式
求大神帮忙看下代码哪里需要修改

https://translate.google.cn/tran ... 0%e8%88%aa%e7%8f%ad

HttpHelper http = new HttpHelper();
                    HttpItem item = new HttpItem()
                    {
                        URL = urls,
                        Method = "GET",
                        Timeout = 100000,
                        ReadWriteTimeout = 30000,
                        IsToLower = false,
                        Cookie = CookieStr,
                        UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
                        Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                        ContentType = "text/html",
                        Host = "translate.google.cn",
                        Referer = "https://translate.google.cn",
                        Allowautoredirect = false,
                        AutoRedirectCookie = false,
                        Postdata = "",
                        //ResultType = ResultType.String,//返回数据类型,是Byte还是String  
                    };
                    HttpResult result = http.GetHtml(item);
                    string input = result.Html;
                    string cookie = result.Cookie;




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2020-6-10 16:57:13 | 显示全部楼层
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
    URL = "https://translate.google.cn/translate_a/single?client=webapp&sl=auto&tl=en&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&dt=gt&otf=2&ssel=3&tsel=3&kc=1&tk=124033.512245&q=%e7%96%ab%e6%83%85%e4%b8%8e%e5%8a%a8%e4%b9%b1%e4%b9%8b%e4%b8%8b%ef%bc%8c%e7%be%8e%e8%82%a1%e4%b8%89%e5%a4%a7%e6%8c%87%e6%95%b0%e9%bd%90%e5%88%9b%e8%bf%91%e4%b8%89%e4%b8%aa%e6%9c%88%e6%96%b0%e9%ab%98%ef%bc%8c%e7%ba%b3%e6%96%af%e8%be%be%e5%85%8b%e6%8c%87%e6%95%b0%e8%b7%9d3%e6%9c%88%e7%9a%84%e5%ba%95%e9%83%a8%e5%b7%b2%e5%8f%8d%e5%bc%b9%e8%bf%9150%ef%bc%8c%e8%b7%9d%e7%a6%bb%e5%8e%86%e5%8f%b2%e6%9c%80%e9%ab%98%e7%82%b9%e4%bd%8d%e7%9a%84%e8%b7%9d%e7%a6%bb%e4%bb%85%e5%89%a91.58%e3%80%82%e7%be%8e%e5%9b%bd%e6%9a%82%e5%81%9c%e6%89%80%e6%9c%89%e4%b8%ad%e5%9b%bd%e5%ae%a2%e8%bf%90%e8%88%aa%e7%8f%ad",//URL     必需项
    Method = "GET",//URL     可选项 默认为Get
    Timeout = 100000,//连接超时时间     可选项默认为100000
    ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
    IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
    Cookie = "",//字符串Cookie     可选项
    UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统     可选项有默认值
    Accept = "text/html, application/xhtml+xml, */*",//    可选项有默认值
    ContentType = "application/json",//返回类型    可选项有默认值
    Referer ="",//来源URL     可选项
    Allowautoredirect = False,//是否根据301跳转     可选项
    AutoRedirectCookie = False,//是否自动处理Cookie     可选项
    //CerPath = "d:\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
    //Connectionlimit = 1024,//最大连接数     可选项 默认为1024
    Postdata = "",//Post数据     可选项GET时不需要写
    //ProxyIp = "192.168.1.105:2020",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数
    //ProxyPwd = "123456",//代理服务器密码     可选项
    //ProxyUserName = "administrator",//代理服务器账户名     可选项
    ResultType = ResultType.String,//返回数据类型,是Byte还是String
};
HttpResult result = http.GetHtml(item);
string html = result.Html;
string cookie = result.Cookie;
        

        /// <summary>
        /// 字节数组生成图片
        /// </summary>
        /// <param name="Bytes">字节数组</param>
        /// <returns>图片</returns>
        private Image byteArrayToImage(byte[] Bytes)
        {
            MemoryStream ms = new MemoryStream(Bytes);
            return Bitmap.FromStream(ms,true);
        }
最重要的是 ContentType = "application/json",//返回类型    可选项有默认值
发表于 2020-6-11 17:05:20 | 显示全部楼层
ContentType的问题,HTTPHelper默认的是text/html,这里浏览器的默认的是application/json,
[C#] 纯文本查看 复制代码
   private string GetHttp20200611165500()
        {
            SufeiUtil.HttpHelper http = new SufeiUtil.HttpHelper();
            SufeiUtil.HttpItem item = new SufeiUtil.HttpItem()
            {
                URL = "https://translate.google.cn/translate_a/single?client=webapp&sl=auto&tl=en&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&dt=gt&otf=2&ssel=3&tsel=3&kc=1&tk=124033.512245&q=%e7%96%ab%e6%83%85%e4%b8%8e%e5%8a%a8%e4%b9%b1%e4%b9%8b%e4%b8%8b%ef%bc%8c%e7%be%8e%e8%82%a1%e4%b8%89%e5%a4%a7%e6%8c%87%e6%95%b0%e9%bd%90%e5%88%9b%e8%bf%91%e4%b8%89%e4%b8%aa%e6%9c%88%e6%96%b0%e9%ab%98%ef%bc%8c%e7%ba%b3%e6%96%af%e8%be%be%e5%85%8b%e6%8c%87%e6%95%b0%e8%b7%9d3%e6%9c%88%e7%9a%84%e5%ba%95%e9%83%a8%e5%b7%b2%e5%8f%8d%e5%bc%b9%e8%bf%9150%ef%bc%8c%e8%b7%9d%e7%a6%bb%e5%8e%86%e5%8f%b2%e6%9c%80%e9%ab%98%e7%82%b9%e4%bd%8d%e7%9a%84%e8%b7%9d%e7%a6%bb%e4%bb%85%e5%89%a91.58%e3%80%82%e7%be%8e%e5%9b%bd%e6%9a%82%e5%81%9c%e6%89%80%e6%9c%89%e4%b8%ad%e5%9b%bd%e5%ae%a2%e8%bf%90%e8%88%aa%e7%8f%ad",
                Method = "GET",
                ContentType = "application/json;charset=utf-8"
            };
            
            SufeiUtil.HttpResult result = http.GetHtml(item);
            string html = result.Html;
            return html;
        }
发表于 2020-6-12 10:21:24 | 显示全部楼层
昨天看时没人回帖,今天一看就有前天的回帖了, ??????
发表于 2020-6-13 11:33:13 | 显示全部楼层
clrscr 发表于 2020-6-12 10:21
昨天看时没人回帖,今天一看就有前天的回帖了, ??????

普通会员回帖需要审核- -
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-20 18:06

© 2014-2021

快速回复 返回顶部 返回列表