C#通过WebClient采集网页出错“System.Net.WebException”类型的未经处理的异常在 System.dll 中发生 其他信息:其他

狼独舞 2020-02-06 07:55:58
在站内看到一篇文章,
利用C#爬取网页HTML数据https://blog.csdn.net/liiukangkang/article/details/83689196
我对应尝试了一下,结果一来就出错了。代码如下。

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

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

private void button1_Click(object sender, EventArgs e)
{
GetData();
}

public void GetData()
{
WebClient web = new WebClient();
web.Encoding = Encoding.UTF8;
string html = web.DownloadString(textBox1.Text);
textBox2.Text = html;
MessageBox.Show(html);
}

}
}


输入任意一个网址后出现一下错误:
“System.Net.WebException”类型的未经处理的异常在 System.dll 中发生

其他信息: 未能找到文件“D:\VS2015\PicDownload\PicDownload\bin\Debug\www.baidu.com”。




百度搜索了很久,没有关于这个错误的(未能找到文件)。

实在没辙了,还请各位大佬出手指点一下。感激不尽。
...全文
1370 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
狼独舞 2020-02-15
  • 打赏
  • 举报
回复
谢谢指点,确实是这个问题,http://的问题
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
你输入的只是www.baidu.com,他默认会以当前路径拼接路径,你改成https://www.baidu.com/或者http://www.baidu.com/就不会错了

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧