【问题标题】:How to download full data in web page如何在网页中下载完整数据
【发布时间】:2014-09-04 13:04:18
【问题描述】:

我正在使用 WebClient 方法。需要本站的具体数据。但是 webclient 下载丢失的数据。我在notepad++中打开这个网站,这个长度314497,但是webclient下载7120。我需要帮助请帮助我。

            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.Data;
            using System.Drawing;
            using System.IO;
            using System.Linq;
            using System.Net;
            using System.Text;
            using System.Threading.Tasks;
            using System.Windows.Forms;

            namespace sampleapp
            {
                public partial class Form1 : Form
                {
                    public Form1()
                    {
                        InitializeComponent();
                        WebClient webClient = new WebClient();
                        string data=webClient.DownloadString(new Uri("blablabla"));
                        MessageBox.Show(data.Length.ToString());
                        textBox1.Text = data;



                    }

伙计们,我正在处理它:

            namespace sampleapp
            {
                public partial class Form1 : Form
                {
                    public Form1()
                    {
                        InitializeComponent();
                    }

                    private void GetWebText(string url)
                    {
                        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
                        request.UserAgent = "A .NET Web Crawler";
                        WebResponse response = request.GetResponse();
                        Stream stream = response.GetResponseStream();
                        StreamReader reader = new StreamReader(stream);
                        string htmlText = reader.ReadToEnd();
                        textBox1.Text = htmlText;
                        MessageBox.Show(htmlText.Length.ToString());


                    }

【问题讨论】:

  • 感谢您的回答,但我是菜鸟,不懂意思:(

标签: c# webclient


【解决方案1】:

您要比较的页面的 HTML 源代码不同。您可以从第一行看到文档类型不一样。一是严格,二是过渡。

这就是字符串长度不同的原因。

如果 URL 相同,这可能是由于传递的用户代理不同,或者会话未保持。

【讨论】:

  • 我正在使用 HttpWebRequest 处理它,感谢您的回答:)
猜你喜欢
  • 1970-01-01
  • 2020-11-22
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-21
  • 2010-12-10
相关资源
最近更新 更多