Tom20081
2018-08-13 11:47
采纳率: 100%
浏览 709

C# 采集网页,浏览器可以打开,程序采集提示错误

网址:https://pgi.kaipanla.com/w12/share/PContent2.html?AID=1548&tag=2&atype=ord
浏览器打开可以正常显示内容,使用WebRequest无法获得网页内容。
请给出demo

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • blownewbee 2018-08-13 12:23
    已采纳
     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Net;
    
    namespace Q697477
    {
        class Program
        {
            public static string PostData(string url, string param)
            {
                string strURL = url;
                System.Net.HttpWebRequest request;
                request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                string paraUrlCoded = param;
                byte[] payload;
                payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
                request.ContentLength = payload.Length;
                Stream writer = request.GetRequestStream();
                writer.Write(payload, 0, payload.Length);
                writer.Close();
                System.Net.HttpWebResponse response;
                response = (System.Net.HttpWebResponse)request.GetResponse();
                System.IO.Stream s;
                s = response.GetResponseStream();
                string StrDate = "";
                string strValue = "";
                StreamReader Reader = new StreamReader(s, Encoding.UTF8);
                while ((StrDate = Reader.ReadLine()) != null)
                {
                    strValue += StrDate + "\r\n";
                }
                return strValue;
            }
            static void Main(string[] args)
            {
                string s = PostData("https://article.kaipanla.com/w1/api/index.php?apiv=w12&PhoneOSNew=3", "c=ForumsMsgJX&a=GetInfo&MsgID=1548&Tag=1");
                Console.WriteLine(s);
            }
        }
    }
    
    
    点赞 打赏 评论
  • blownewbee 2018-08-13 12:27

    图片说明

     {"Msg":{"ID":1548,"Title":"\u3010\u590d\u76d8\u3011\u6da8\u505c\u6d45\u679004.27\uff08\u6587\u5b57\u7248\uff09","MsgType":2,"CreateTime":1524826266,"VoteCount":54,"ShareCount":46,"Content":"<p><strong><span style=\"color: rgb(192, 0, 0);\">\u4e00\u3001\u533b\u836f&amp;\u533b\u7597\uff1a4<\/span><\/strong><\/p><p>002524 <span class=\"noml_StoBk\" data-sid=\"002524\" data-name=\"\u5149\u6b63\u96c6\u56e2\" data-type=\"stl\">\u5149\u6b63\u96c6\u56e2<\/span>\uff1a<strong><span style=\"color: rgb(192, 0, 0);\">\u4e8c\u8fde\u677f\uff0c<\/span><\/strong>\u5e76\u8d2d\u65b0\u89c6\u754c\u773c\u79d151%\u7684\u80a1\u6743\uff0c\u8d85\u8dcc\uff0c\u5e84\u80a1<\/p><p>002365 <span class=\"noml_StoBk\" data-sid=\"002365\" data-name=\"\u6c38\u5b89\u836f\u4e1a\" data-type=\"stl\">\u6c38\u5b89\u836f\u4e1a<\/span>\uff1a\u5316\u5b66\u5236\u836f+\u8d85\u8dcc\u4f4e\u4f4d<\/p><p>300519 <span class=\"noml_StoBk\" data-sid=\"300519\" data-name=\"\u65b0\u5149\u836f\u4e1a\" data-type=\"stl\">\u65b0\u5149\u836f\u4e1a<\/span>\uff1a\u4e2d\u6210\u836f\u7814\u53d1\u751f\u4ea7+\u8d85\u8dcc\u4f4e\u4f4d<\/p><p>600332 &nbsp; \u767d\u4e91\u5c71\uff1a\u533b\u836f+\u6743\u91cd\uff0c\u62df\u65a59000\u4e07\u5143\u53c2\u8bbe\u767d\u4e91\u5c71<span class=\"noml_StoBk\" data-sid=\"002727\" data-name=\"\u4e00\u5fc3\u5802\" data-type=\"stl\">\u4e00\u5fc3\u5802<\/span>\uff0c\u52a0\u901f\u5e03\u5c40\u533b\u836f\u8fde\u9501\u7ec8\u7aef<\/p><p><strong><span style=\"color: rgb(192, 0, 0);\">\u4e8c\u3001\u4f53\u80b2\u4ea7\u4e1a\uff1a2<\/span><\/strong><br><\/p><p>300526 <span class=\"noml_StoBk\" data-sid=\"300526\" data-name=\"\u4e2d\u6f5c\u80a1\u4efd\" data-type=\"stl\">\u4e2d\u6f5c\u80a1\u4efd<\/span>\uff1a<strong><span style=\"color: rgb(192, 0, 0);\">3\u59292\u677f\uff0c<\/span><\/strong>\u4e3b\u8425\u6f5c\u6c34\u88c5\u5907\u5236\u9020&nbsp;<\/p><p>300162 <span class=\"noml_StoBk\" data-sid=\"300162\" data-name=\"\u96f7\u66fc\u80a1\u4efd\" data-type=\"stl\">\u96f7\u66fc\u80a1\u4efd<\/span>\uff1a\u4e16\u754c\u676f\u6982\u5ff5+\u5c0f\u95f4\u8dddLED<\/p><p><strong><span style=\"color: rgb(192, 0, 0);\">\u4e09\u3001\u6b21\u65b0\u80a1 \uff1a2<\/span><\/strong><\/p><p>300729 <span class=\"noml_StoBk\" data-sid=\"300729\" data-name=\"\u4e50\u6b4c\u80a1\u4efd\" data-type=\"stl\">\u4e50\u6b4c\u80a1\u4efd<\/span>\uff1a\u8fdc\u7aef\u6b21\u65b0\u80a1\uff0c\u4eba\u4f53\u5de5\u7a0b\u5b66\u4ea7\u54c1\u7684\u7814\u53d1\u3001\u751f\u4ea7\u53ca\u9500\u552e\u3002<\/p><p>603214 &nbsp; \u7231\u5a74\u5ba4\uff1a<span style=\"color: rgb(192, 0, 0);\"><strong>4\u59292\u677f\uff0c<\/strong><\/span>\u5f00\u677f\u6b21\u65b0\uff0c\u4e3b\u8425\u6bcd\u5a74\u5546\u54c1\u9500\u552e\uff0c\u5e76\u63d0\u4f9b\u6bcd\u5a74\u670d\u52a1<\/p><p><strong><span style=\"color: rgb(192, 0, 0);\">\u56db\u3001\u5176\u4ed6\uff1a9<\/span><\/strong><\/p><p>600476 <span class=\"noml_StoBk\" data-sid=\"600476\" data-name=\"\u6e58\u90ae\u79d1\u6280\" data-type=\"stl\">\u6e58\u90ae\u79d1\u6280<\/span>\uff1a<strong><span style=\"color: rgb(192, 0, 0);\">\u4e8c\u8fde\u677f\uff0c<\/span><\/strong>\u56fd\u4ea7\u8f6f\u4ef6+\u96c4\u5b89\uff0c\u5b9e\u63a7\u4eba\u662f\u4e2d\u56fd\u90ae\u653f\u96c6\u56e2\u516c\u53f8\uff0c\u4e3b\u8425\u5927\u6570\u636e\u670d\u52a1\u53ca\u8f6f\u4ef6\u5f00\u53d1<\/p><p>600555 <span class=\"noml_StoBk\" data-sid=\"600555\" data-name=\"\u6d77\u822a\u521b\u65b0\" data-type=\"stl\">\u6d77\u822a\u521b\u65b0<\/span>\uff1a\u6d77\u5357+\u9a6c\u5f69<\/p><p>000820 <span class=\"noml_StoBk\" data-sid=\"000820\" data-name=\"\u795e\u96fe\u8282\u80fd\" data-type=\"stl\">\u795e\u96fe\u8282\u80fd<\/span>\uff1a\u73af\u4fdd+\u8d85\u8dcc\u53cd\u5f39<\/p><p>300155 &nbsp; <span class=\"noml_StoBk\" data-sid=\"300155\" data-name=\"\u5b89\u5c45\u5b9d\" data-type=\"stl\">\u5b89\u5c45\u5b9d<\/span>\uff1a\u667a\u6167\u57ce\u5e02+\u7269\u8054\u7f51+\u8d85\u8dcc\u53cd\u5f39<\/p><p>002795 <span class=\"noml_StoBk\" data-sid=\"002795\" data-name=\"\u6c38\u548c\u667a\u63a7\" data-type=\"stl\">\u6c38\u548c\u667a\u63a7<\/span>\uff1a\u8d85\u8dcc\u53cd\u5f39\uff0c\u4e3b\u8425\u6d41\u4f53\u63a7\u5236\u8bbe\u5907\u53ca\u5668\u6750\u7684\u7814\u53d1\u3001\u5236\u9020\u548c\u9500\u552e<\/p><p>000995 \u7687\u53f0\u9152\u4e1a\uff1a\u767d\u9152+\u8d85\u8dcc\u53cd\u5f39\uff0c\u4e3b\u8425\u767d\u9152\u3001\u8461\u8404\u9152\u7684\u751f\u4ea7<\/p><p>300251 <span class=\"noml_StoBk\" data-sid=\"300251\" data-name=\"\u5149\u7ebf\u4f20\u5a92\" data-type=\"stl\">\u5149\u7ebf\u4f20\u5a92<\/span>\uff1a\u4f20\u5a92+\u521b\u4e1a\u677f\u6307\u6807\u80a1\uff0c\u4e00\u5b63\u5ea6\u4e1a\u7ee9\u9884\u589e10\u500d<\/p><p>000691 <span class=\"noml_StoBk\" data-sid=\"000691\" data-name=\"\u4e9a\u592a\u5b9e\u4e1a\" data-type=\"stl\">\u4e9a\u592a\u5b9e\u4e1a<\/span>\uff1a\u623f\u5730\u4ea7+\u8d85\u8dcc\uff0c\u5e84\u80a1<\/p><p>002112 <span class=\"noml_StoBk\" data-sid=\"002112\" data-name=\"\u4e09\u53d8\u79d1\u6280\" data-type=\"stl\">\u4e09\u53d8\u79d1\u6280<\/span>\uff1a\u8d85\u8dcc\u53cd\u5f39+\u7535\u6c14\u8bbe\u5907\uff0c\u4e2d\u62a5\u9884\u589e 73.75%~100%<\/p><p><img src=\"https:\/\/notesimg.kaipanla.com\/notesimg\/2018\/04\/27\/aAbBegGHkLNoqQuvxXyY.png\" title=\"abcdEiIKlLOPQSUWx.png\" alt=\"blob.png\"><\/p>","Author":{"ID":"55","Name":"\u809a\u5927\u4fa0","HeadPic":"http:\/\/icon.ipail.com\/head\/9\/icon_98903.jpg?time=1522473013","Desc":""},"imgList":["https:\/\/resi.kaipanla.com\/uploadImg\/ForumsAuthorJX\/Formal\/dudaxia.png"],"Like":0,"Share":0,"Login":0},"CurTime":1534163261,"LikeMsg":[{"ID":"2156","Title":"\u3010\u590d\u76d8\u3011\u5f00\u76d8\u5566\u6da8\u505c\u677f\u590d\u76d8\uff0808.13\uff09","Type":"2"},{"ID":"2155","Title":"\u3010\u5206\u6790\u3011\u76d8\u9762\u6838\u5fc3\u68b3\u7406\uff0808.13\uff09","Type":"2"},{"ID":"2154","Title":"\u3010\u590d\u76d8\u3011\u6da8\u505c\u6d45\u679018.08.13\uff08\u6587\u5b57\u7248\uff09","Type":"2"},{"ID":"2153","Title":"\u3010\u5fc5\u770b\u3011\u4e00\u56fe\u590d\u76d8\uff0808.13\uff09","Type":"2"},{"ID":"2150","Title":"\u3010\u590d\u76d8\u7b56\u7565\u3011\u7b51\u5e95\u9636\u6bb5 \u9707\u8361\u53cd\u590d\uff0808.12\uff09","Type":"2"}],"errcode":"0","t":0.043682}
    
    Press any key to continue . . .
    

    其中 \u3010\u590d\u76d8\u3011\u6da8\u505c\u6d45\u679004.27\uff08\u6587\u5b57\u7248\uff09 等等可以在
    http://tool.oschina.net/encode?type=3
    查看解码
    图片说明

    点赞 打赏 评论

相关推荐 更多相似问题