当前位置: 首页 > 软件库 > 应用工具 > 浏览器 >

SimpleBrowser

浏览器引擎
授权协议 BSD
开发语言 .NET
所属分类 应用工具、 浏览器
软件类型 开源软件
地区 不详
投 递 者 红弘盛
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

SimpleBrowser是专门为自动化任务而设计的一个灵活而直观的浏览器引擎,内置.Net 4 framework

示例代码:

class Program
{
    static void Main(string[] args)
    {
        var browser = new Browser();
        try
        {
            // log the browser request/response data to files so we can interrogate them in case of an issue with our scraping
            browser.RequestLogged += OnBrowserRequestLogged;
            browser.MessageLogged += new Action<Browser, string>(OnBrowserMessageLogged);

            // we'll fake the user agent for websites that alter their content for unrecognised browsers
            browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";

            // browse to GitHub
            browser.Navigate("http://github.com/");
            if(LastRequestFailed(browser)) return; // always check the last request in case the page failed to load

            // click the login link and click it
            browser.Log("First we need to log in, so browse to the login page, fill in the login details and submit the form.");
            var loginLink = browser.Find("a", FindBy.Text, "Login");
            if(!loginLink.Exists)
                browser.Log("Can't find the login link! Perhaps the site is down for maintenance?");
            else
            {
                loginLink.Click();
                if(LastRequestFailed(browser)) return;

                // fill in the form and click the login button - the fields are easy to locate because they have ID attributes
                browser.Find("login_field").Value = "youremail@domain.com";
                browser.Find("password").Value = "yourpassword";
                browser.Find(ElementType.Button, "name", "commit").Click();
                if(LastRequestFailed(browser)) return;

                // see if the login succeeded - ContainsText() is very forgiving, so don't worry about whitespace, casing, html tags separating the text, etc.
                if(browser.ContainsText("Incorrect login or password"))
                {
                    browser.Log("Login failed!", LogMessageType.Error);
                }
                else
                {
                    // After logging in, we should check that the page contains elements that we recognise
                    if(!browser.ContainsText("Your Repositories"))
                        browser.Log("There wasn't the usual login failure message, but the text we normally expect isn't present on the page");
                    else
                    {
                        browser.Log("Your News Feed:");
                        // we can use simple jquery selectors, though advanced selectors are yet to be implemented
                        foreach(var item in browser.Select("div.news .title"))
                            browser.Log("* " + item.Value);
                    }
                }
            }
        }
        catch(Exception ex)
        {
            browser.Log(ex.Message, LogMessageType.Error);
            browser.Log(ex.StackTrace, LogMessageType.StackTrace);
        }
        finally
        {
            var path = WriteFile("log-" + DateTime.UtcNow.Ticks + ".html", browser.RenderHtmlLogFile("SimpleBrowser Sample - Request Log"));
            Process.Start(path);
        }
    }

    static bool LastRequestFailed(Browser browser)
    {
        if(browser.LastWebException != null)
        {
            browser.Log("There was an error loading the page: " + browser.LastWebException.Message);
            return true;
        }
        return false;
    }

    static void OnBrowserMessageLogged(Browser browser, string log)
    {
        Console.WriteLine(log);
    }

    static void OnBrowserRequestLogged(Browser req, HttpRequestLog log)
    {
        Console.WriteLine(" -> " + log.Method + " request to " + log.Url);
        Console.WriteLine(" <- Response status code: " + log.ResponseCode);
    }

    static string WriteFile(string filename, string text)
    {
        var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"));
        if(!dir.Exists) dir.Create();
        var path = Path.Combine(dir.FullName, filename);
        File.WriteAllText(path, text);
        return path;
    }
}
  • #include "browser.h" #include "browserwindow.h" #include <QApplication> QString getCommandLineUrlArgument() { const QStringList args = QCoreApplication::arguments(); if (args.count() > 1) {

 相关资料
  • JavaScript代码嵌入网页的方法 直接添加代码块 加载外部脚本 行内代码 外部脚本的加载 网页底部加载 多个脚本的加载 defer属性 async属性 脚本的动态嵌入 加载使用的协议 JavaScript虚拟机 单线程模型 Event Loop 任务队列 参考链接 浏览器通过内置的JavaScript引擎,读取网页中的代码,对其处理后运行。 JavaScript代码嵌入网页的方法 在网页中嵌

  • 浏览器工作原理。 目录 排版引擎 ​渲染​ JavaScript 引擎 ​并发模型​ ​内存管理​ ​执行环境​ 网络通信 ​缓存​ ​Cookie​ ​跨源资源共享​ 安全 ​同源策略​ Web APIs ​事件​ ​存储​ ​定时器​ ​Fetch​ 文档操作 数据通信 图形处理 音视频处理

  • 设计开发的页面与网站需要在浏览器上预览与调试。推荐使用 Chrome 浏览器。 Chrome Safari Firefox Edge(IE)

  • 可浏览互联网Web网页的应用程序。 浏览器的LiveArea™ 浏览Web网页 开启更多窗口 使用书签及历史记录 设定浏览器 上传

  • 浏览工具 JS 浏览工具: URI.js platform.js history.js html2canvas 参考工具(查看浏览器是否支持某特性) caniusee.com HTML5 Please HTML5 test Browserscope webbrowsercompatibility.com iwanttouse.com/ Platform status Browser support

  • 由于JavaScript的出现就是为了能在浏览器中运行,所以,浏览器自然是JavaScript开发者必须要关注的。 目前主流的浏览器分这么几种: IE 6~11:国内用得最多的IE浏览器,历来对W3C标准支持差。从IE10开始支持ES6标准; Chrome:Google出品的基于Webkit内核浏览器,内置了非常强悍的JavaScript引擎——V8。由于Chrome一经安装就时刻保持自升级,所以