This article is a mirror article of machine translation, please click here to jump to the original article.

View: 29050|Reply: 2

[WinForm] Use CefSharp to access websites in C#

[Copy link]
Posted on 4/2/2019 8:31:40 PM | | | |
I actually want to use CefSharp to access website pages, and then grab the html source code for analysis, if you use the built-in WebBrowser control, there may be some js incompatible errors.

CefSharp allows you to embed Chromium in .NET applications. It is a lightweight .NET wrapper around the Chromium Embedded Framework (CEF) by Marshall A. Greenblatt. About 30% of the bindings are written in C++/CLI, and most of the code here is in C#. It can be used from C# or VB or any other CLR language. CefSharp provides WPF and WinForms web browser control implementations.

GitHub address:The hyperlink login is visible.

First, I use VS to create a new winform project with the following environment:

  • . .NET framework version: 4.6.2
  • Visual Studio 2013: And above, I'm using vs2017 here



The nuget command is as follows:

After execution is complete, the program automatically adds dependency packages as follows:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="cef.redist.x64" version="3.3578.1870" targetFramework="net462" />
  <package id="cef.redist.x86" version="3.3578.1870" targetFramework="net462" />
  <package id="CefSharp.Common" version="71.0.2" targetFramework="net462" />
  <package id="CefSharp.WinForms" version="71.0.2" targetFramework="net462" />
</packages>

After the installation is completed, the compilation project will report the following error:

CefSharp.Common contains unmanaged resoures, set your project and solution platform to x86 or x64. Alternatively for AnyCPU Support seeThe hyperlink login is visible.

I saw a solution on the Internet that says change the active solution platform to x86 (CEF cannot adapt to x86 | x64, you must choose a target), and the target platform must also be consistent with the solution platform.
Starting with CefSharp 51, you can use CefSharp with AnyCPU, but it doesn't work alone because you need to make some changes in 2 specific files.

According to the method of netizens, it should be solved, I didn't try, in fact, cef already supports AnyCPU, but it needs to be configured, the configuration scheme is as follows:

1: First right-click on the project, uninstall the solution, edit the .csproj file of the project, and add it to <PropertyGroup>the first node:



2: After the addition is complete, reload the project and add the following configuration in app.config:



3: Before calling Cef.Initialize, configure the browser startup path with the following code:

Solution Reference:The hyperlink login is visible.

The completed code is as follows:


Run Projects:


Resources:https://ourcodeworld.com/article ... informs-application

(End)







Previous:java gets the Object property type, property name, and property value
Next:Visual Studio 2019 offline download and installation tutorial
Posted on 4/2/2019 8:46:35 PM |
Support the owner, thank you for sharing.
Posted on 4/8/2019 11:44:58 PM |
I've been paying attention to CefSharp, but I don't have a better and simpler example to understand. Thanks for sharing
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com