大家好,我想获取页面的源代码,但是 CeFSharp 在输出时为我打开了一个记事本,带有 html ... 告诉我如何修复它,以便仅在变量中输入数据。
using System;
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;
using CefSharp;
using CefSharp.WinForms;
namespace Rate_Scanner
{
public partial class FonbetForm : Form
{
ChromiumWebBrowser chrome;
public FonbetForm()
{
InitializeComponent();
InitializeChromeBrowser();
}
private void InitializeChromeBrowser()
{
CefSettings cefSettings = new CefSettings();
Cef.Initialize(cefSettings);
chrome = new ChromiumWebBrowser("https://www.youtube.com/watch?v=UOyYR72R7Ik");
chrome.Dock = DockStyle.Fill;
this.Controls.Add(chrome);
}
private string FonbetPage()
{
chrome.ViewSource();
var html = "";
chrome.GetSourceAsync().ContinueWith(taskHtml =>
{
html = taskHtml.Result;
});
return html;
}
private void button1_Click(object sender, EventArgs e)
{
FonbetPage();
}
}
}
不起作用,因为这个
html = taskHtml.Result;比这个晚触发return html;。但这chrome.ViewSource();可以完全删除。然后事实证明根本不需要单独的方法,因为它只有一行。
异步编程。