【问题标题】:Winforms WebClient not getting the webpage properlyWinforms WebClient 无法正确获取网页
【发布时间】:2022-01-22 09:23:33
【问题描述】:

该页面最初显示价格和商品,但在获取结果时只看到标题。

private void Form1_Load(object sender, EventArgs e)
        {
            string q = "https://www.g2g.com/categories/counter-strike-global-offensive-item";
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("user-agent", "foo");
                client.UseDefaultCredentials = true;
                client.Headers[HttpRequestHeader.UserAgent] = "Mozilla / 5.0(Windows NT 10.0; Win64; x64; rv: 44.0) Gecko / 20100101 Firefox / 44.0";
                client.Encoding = Encoding.UTF8;
                string htmlcode = client.DownloadString(q);
                asss.Text = htmlcode;
            }
        }
    } 

怎么样

photo

我得到了什么

photo

【问题讨论】:

    标签: winforms web webclient


    【解决方案1】:

    您似乎忘记使用呈现 HTML 和执行 JavaScript 的控件(如 WebBrowser 或更新的 WebView2)而不是普通的 TextBox 或 LinkLabel(如纯文本内容所示)。

    您可以通过WebBrowser.DocumentText设置您使用WebClient检索到的页面内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-11
      • 2013-12-22
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 2020-06-01
      相关资源
      最近更新 更多