CefSharp获取页面Html代码的两种方式
CefSharp在NuGet的简介是“The CefSharp Chromium-based browser component”,机翻的意思就是“基于Cefsharp Chromium的浏览器组件”
第一种方法 就是执行JavaScript代码获取当前html代码
StringBuilder sb = new StringBuilder();
sb.AppendLine("function tempFunction() {");
//sb.AppendLine(" return document.body.innerHTML; ");
sb.AppendLine(" return document.getElementsByTagName('html')[0].innerHTML; ");
sb.AppendLine("}");
sb.AppendLine("tempFunction();");
var task01 = browser.GetBrowser().GetFrame(browser.GetBrowser().GetFrameNames()[]).EvaluateScriptAsync(sb.ToString());
task01.ContinueWith(t =>
{
if (!t.IsFaulted)
{
var response = t.Result;
if (response.Success == true)
{
if (response.Result != null)
{
string resultStr = response.Result.ToString();
}
}
}
});
第二种方法 是利用CefSharp.IFrame.GetSourceAsync()方法
/// <summary>
/// 页面加载结束
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
var task02 = e.Frame.GetSourceAsync();
task02.ContinueWith(t =>
{
if (!t.IsFaulted)
{
string resultStr = t.Result;
}
});
}
我这里是在Browser_FrameLoadEnd事件中直接获取的IFrame,
GetSourceAsync()方法我简单翻译了一下
//
// 摘要:
// Retrieve this frame's HTML source as a string sent to the specified visitor.
// 检索此框架的HTML源代码以字符串形式发送给指定访问者。
//
// 返回结果:
// a System.Threading.Tasks.Task`1 that when executed returns this frame's HTML
// source as a string.
// 一个线程任务,执行时将此框架的HTML源文件作为字符串返回。
Task<string> GetSourceAsync();
CefSharp获取页面Html代码的两种方式的更多相关文章
- springboot项目启动成功后执行一段代码的两种方式
springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springf ...
- js实现页面跳转的两种方式
CreateTime--2017年8月24日08:13:52Author:Marydon js实现页面跳转的两种方式 方式一: window.location.href = url 说明:我们常用 ...
- js中获取页面元素节点的几种方式
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- android启动第一个界面时即闪屏的核心代码(两种方式)
闪屏,就是SplashScreen,也能够说是启动画面,就是启动的时候,闪(展示)一下,持续数秒后.自己主动关闭. 第一种方式: android的实现很easy,使用Handler对象的postDe ...
- html页面保存数的两种方式
原文链接:https://blog.csdn.net/qq_37936542/article/details/78866755 需求:微信开发时,在某个页面授权获取用户的openid,但是每次刷新页面 ...
- C++调用C代码的两种方式
由于C++支持函数重载,在编译函数代码的时候会加上参数类型的信息,而C编译只有函数名信息,导致C++直接调用C代码在链接的时候会出现函数未定义的问题.解决这种问题有两种方法.方法一:在写C代码的时候考 ...
- web项目中实现页面跳转的两种方式
<a href="javascript:"></a>跳转在网页本身,URL不改变 <a href="#"></a> ...
- python编写的banner获取代码的两种方式
1.无选项和帮助信息 #!/usr/bin/env python #coding:utf-8 import socket import sys import os from threading imp ...
- Struts2获取Servlet的api的两种方式,解决ParameterAware过时的问题
servlet API通过ActionContext进行获取 Struts2对HttpServletRequest,HttpSession和ServletContext进行了封装,构造了3个Map对象 ...
随机推荐
- Asp 6种页面转向方法
asp.net 页面转向方法其实就是两种 服务器端转向和客户端转向 客户端转向实质上是指由浏览器直接向服务器端重新发送一个请求. 而服务器端转向是指服务器内部进行页面的跳转. 服务器端转向和客户端转向 ...
- [Libre 6282] 数列分块入门 6 (分块)
原题:传送门 code: //By Menteur_Hxy #include<cstdio> #include<iostream> #include<algorithm& ...
- find命令扩展
1.1 方法一 |xargs 通过|xargs将前面命令的执行结果传给后面. [root@znix ~]# find /clsn/ -type f -name "*.sh" |x ...
- ubuntu 下jrtplib编译
我本来想用最新的 jrtplib-3.9.1和jthread-1.3.1,可是最新的那两个版本中都是用cmake进行配置的,我搞了好久,查了好多资料也没有解决交叉编译的问题,无奈,只能选用比较老的两个 ...
- Python - Datacamp - Introduction to Matplotlib
Python - Datacamp - Introduction to Matplotlib Datacamp: https://www.datacamp.com/ # 1.py 基本matplotl ...
- C# litJson 使用方法
对一般数据进行序列化和反序列化操作 static void jsonTest() { // JsonData jd = new JsonData(); jd["result"] = ...
- CF789C. Functions again
/* CF789C. Functions again http://codeforces.com/contest/789/problem/C 水题 题意:求数组中的连续和的最大值 */ #includ ...
- CF449 C. Jzzhu and Apples
/* http://codeforces.com/problemset/problem/449/C cf 449 C. Jzzhu and Apples 数论+素数+贪心 */ #include &l ...
- BA-WG-泰豪发电机
泰豪发电机的控制主板有2个端口,一个是RS232端口,一个是RS485端口,通常接网关需要将这个RS485的端口调整为modbus协议输出,再将modbus协议通过网关转换为bacnet / ip协议 ...
- CF43A Football
CF43A Football 题意翻译 题目大意 两只足球队比赛,现给你进球情况,问哪支队伍赢了. 第一行一个整数nn (1\leq n\leq 1001≤n≤100 ),表示有nn 次进球,接下来n ...