学堂 学堂 学堂公众号手机端

要获取网页内容,你可以使用WebBrowser控件的Document属性。下面是一个简单的示例

lewis 1年前 (2024-04-08) 阅读数 4 #技术

要获取网页内容,你可以使用WebBrowser控件的Document属性。下面是一个简单的示例:

usingSystem; usingSystem.Windows.Forms; namespaceWebBrowserExample { publicpartialclassForm1:Form { publicForm1() { InitializeComponent(); } privatevoidForm1_Load(objectsender,EventArgse) { webBrowser1.Navigate("https://www.example.com"); } privatevoidwebBrowser1_DocumentCompleted(objectsender,WebBrowserDocumentCompletedEventArgse) { //获取网页内容 stringhtml=webBrowser1.DocumentText; Console.WriteLine(html); } } }

在上面的示例中,Form加载时,我们导航到一个URL。然后,当网页加载完成后,我们可以通过DocumentCompleted事件来获取网页内容。在该事件处理程序中,我们通过DocumentText属性获取网页的HTML内容。


版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门