dags att checka in
This commit is contained in:
14
PuppeteerSharpTest/DtoEst.cs
Normal file
14
PuppeteerSharpTest/DtoEst.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PuppeteerSharpTest
|
||||
{
|
||||
public class DtoEst
|
||||
{
|
||||
public decimal EstBetrag { get; set; }
|
||||
public decimal EstProzentsatz { get; set; }
|
||||
}
|
||||
}
|
||||
87
PuppeteerSharpTest/Form1.Designer.cs
generated
Normal file
87
PuppeteerSharpTest/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
namespace PuppeteerSharpTest
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.rtbWatcher = new System.Windows.Forms.RichTextBox();
|
||||
this.btnScrape = new System.Windows.Forms.Button();
|
||||
this.txtNettoUmsatz = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// rtbWatcher
|
||||
//
|
||||
this.rtbWatcher.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.rtbWatcher.Location = new System.Drawing.Point(12, 12);
|
||||
this.rtbWatcher.Name = "rtbWatcher";
|
||||
this.rtbWatcher.Size = new System.Drawing.Size(776, 494);
|
||||
this.rtbWatcher.TabIndex = 0;
|
||||
this.rtbWatcher.Text = "";
|
||||
//
|
||||
// btnScrape
|
||||
//
|
||||
this.btnScrape.Location = new System.Drawing.Point(377, 507);
|
||||
this.btnScrape.Name = "btnScrape";
|
||||
this.btnScrape.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnScrape.TabIndex = 1;
|
||||
this.btnScrape.Text = "Start";
|
||||
this.btnScrape.UseVisualStyleBackColor = true;
|
||||
this.btnScrape.Click += new System.EventHandler(this.btnScrape_Click);
|
||||
//
|
||||
// txtNettoUmsatz
|
||||
//
|
||||
this.txtNettoUmsatz.Location = new System.Drawing.Point(84, 513);
|
||||
this.txtNettoUmsatz.Name = "txtNettoUmsatz";
|
||||
this.txtNettoUmsatz.Size = new System.Drawing.Size(100, 23);
|
||||
this.txtNettoUmsatz.TabIndex = 2;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 534);
|
||||
this.Controls.Add(this.txtNettoUmsatz);
|
||||
this.Controls.Add(this.btnScrape);
|
||||
this.Controls.Add(this.rtbWatcher);
|
||||
this.Name = "Form1";
|
||||
this.Text = "Puppeteer";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.RichTextBox rtbWatcher;
|
||||
private System.Windows.Forms.Button btnScrape;
|
||||
private System.Windows.Forms.TextBox txtNettoUmsatz;
|
||||
}
|
||||
}
|
||||
|
||||
87
PuppeteerSharpTest/Form1.cs
Normal file
87
PuppeteerSharpTest/Form1.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using PuppeteerSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PuppeteerSharpTest
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void btnScrape_Click(object sender, EventArgs e)
|
||||
{
|
||||
var result = await LoadXXXAsync();
|
||||
|
||||
}
|
||||
|
||||
private async Task<DtoEst> LoadXXXAsync()
|
||||
{
|
||||
// downloads chromium to the local project, needed by Puppeteer Sharp for execution, takes about 2 min!
|
||||
await new BrowserFetcher().DownloadAsync();
|
||||
// await new BrowserFetcher().DownloadAsync(DefaultChromiumRevision);
|
||||
|
||||
DtoEst dto = new DtoEst();
|
||||
//var url = "https://www.xxxxxx.xhtml";
|
||||
var url = "https://www.bmf-steuerrechner.de/ekst/eingabeformekst.xhtml";
|
||||
|
||||
#region SELECTORS
|
||||
// https://stackoverflow.com/questions/45110893/select-elements-by-attributes-with-colon
|
||||
// use css escapes: https://mothereff.in/css-escapes
|
||||
string id_checkbox_IsMarried = "bmf_form_ekst:ekst_pv:0";
|
||||
string id_input_Umsatz = "bmf_form_ekst:ekst_zve";
|
||||
string id_button_Submit2 = @"#bmf_form_ekst\3A income_ekst";
|
||||
string NettoUmsatz = txtNettoUmsatz.Text;
|
||||
#endregion
|
||||
|
||||
//// This statement downloads and installs chromium
|
||||
//await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
||||
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
{
|
||||
Headless = true
|
||||
});
|
||||
|
||||
using (var page = await browser.NewPageAsync())
|
||||
{
|
||||
// load page
|
||||
await page.GoToAsync(url);
|
||||
// wait for element to be there
|
||||
await page.WaitForExpressionAsync($"document.getElementById('{id_input_Umsatz}')!=null");
|
||||
await page.EvaluateExpressionAsync($"document.getElementById('{id_input_Umsatz}').value = '{NettoUmsatz}';");
|
||||
// get element value
|
||||
var val = await page.EvaluateFunctionAsync<string>($"()=>document.getElementById('{id_input_Umsatz}').value");
|
||||
// wait for element to be there
|
||||
await page.WaitForExpressionAsync($"document.getElementById('{id_checkbox_IsMarried}')!=null");
|
||||
await page.EvaluateExpressionAsync($"document.getElementById('{id_checkbox_IsMarried}').checked = false;");
|
||||
|
||||
await page.ClickAsync(id_button_Submit2);
|
||||
// wait for redirect
|
||||
await page.WaitForNavigationAsync();
|
||||
// get value from element
|
||||
var strValueEst = await page.EvaluateFunctionAsync<string>("()=>document.querySelector('#ui-id-4 > div.ekst_ergebnis > div:nth-child(6) > table > tbody > tr:nth-child(3) > td:nth-child(2) > strong').textContent");
|
||||
// get value from element
|
||||
var strValueEstPercent = await page.EvaluateFunctionAsync<string>("()=>document.querySelector('#ui-id-4 > div.ekst_ergebnis > div:nth-child(6) > table > tbody > tr:nth-child(3) > td:nth-child(3) > strong').textContent");
|
||||
|
||||
var deDE = new CultureInfo("de-DE");
|
||||
|
||||
Decimal.TryParse(strValueEst.TrimEnd(" Euro".ToCharArray()), NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, deDE, out var decValueEst);
|
||||
Decimal.TryParse(strValueEstPercent.TrimEnd(" %".ToCharArray()), NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, deDE, out var decValueEstPercent);
|
||||
|
||||
dto.EstBetrag = decValueEst;
|
||||
dto.EstProzentsatz = decValueEstPercent;
|
||||
}
|
||||
|
||||
return await Task.FromResult(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
60
PuppeteerSharpTest/Form1.resx
Normal file
60
PuppeteerSharpTest/Form1.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
23
PuppeteerSharpTest/Program.cs
Normal file
23
PuppeteerSharpTest/Program.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PuppeteerSharpTest
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
||||
13
PuppeteerSharpTest/PuppeteerSharpTest.csproj
Normal file
13
PuppeteerSharpTest/PuppeteerSharpTest.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PuppeteerSharp" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user