【发布时间】:2021-02-19 20:59:55
【问题描述】:
我正在尝试下载一个网站源代码,一按按钮开始检索,程序就会无限卡住
我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (WebClient client = new WebClient())
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
string html = client.DownloadString("https://www.finanzen.net/termine/unternehmen/");
MessageBox.Show(html);
}
}
}
}
我该如何解决这个问题?任何帮助表示赞赏:)
【问题讨论】:
-
您可以在 Visual Studio 中设置断点并查看导致此行为的原因。
-
WebClient已经过时了,你应该改用HttpClient
标签: c# html web-scraping webclient