22// Updated 03.01.2025 by @dirkhe
33// Updated 18.01.2025 by @dirkhe - Logging added
44
5+ /** start date for historic rates when no min date is set on the input */
6+ const DEFAULT_START_DATE = '2020-01-01' ;
7+
58var ArrayList = java . util . ArrayList ;
69
710var fetcher ;
@@ -59,7 +62,11 @@ function prepare(
5962 searchButton = page . getElementById ( "request-historic-price" ) ;
6063
6164 input = page . getElementById ( "fromDate" ) ;
62- input . setValue ( input . getMin ( ) ) ;
65+ if ( input . getMin ( ) ) {
66+ input . setValue ( input . getMin ( ) ) ;
67+ } else {
68+ input . setValue ( DEFAULT_START_DATE ) ;
69+ }
6370
6471 input = page . getElementById ( "toDate" ) ;
6572 input . setValue ( input . getMax ( ) ) ;
@@ -68,39 +75,60 @@ function prepare(
6875 Packages . de . willuhn . logging . Logger . debug ( "suche Link historische Kurse" ) ;
6976 links = page . getAnchorByText ( "Historische Kurse" ) ;
7077 page = links . click ( ) ;
71- } catch ( error ) {
72- Packages . de . willuhn . logging . Logger . debug ( "suche Link Kurse & Realtime" ) ;
73- links = page . getAnchorByText ( "Kurse & Realtime" ) ;
74- page = links . click ( ) ;
75- Packages . de . willuhn . logging . Logger . debug ( "suche Link historische Kurse" ) ;
76- links = page . getAnchorByText ( "Historische Kurse" ) ;
77- page = links . click ( ) ;
78+ } catch ( error ) {
79+ try {
80+ Packages . de . willuhn . logging . Logger . debug ( "suche Link Kurse & Realtime" ) ;
81+ links = page . getAnchorByText ( "Kurse & Realtime" ) ;
82+ page = links . click ( ) ;
83+ Packages . de . willuhn . logging . Logger . debug ( "suche Link historische Kurse" ) ;
84+ links = page . getAnchorByText ( "Historische Kurse" ) ;
85+ page = links . click ( ) ;
86+ } catch ( error2 ) {
87+ // navigate to historic rates for "Zertifikate"
88+ Packages . de . willuhn . logging . Logger . debug ( "suche Link Historisch" ) ;
89+ links = page . getAnchorByText ( "Historisch" ) ;
90+ page = links . click ( ) ;
91+ }
92+ }
93+ try {
94+ Packages . de . willuhn . logging . Logger . debug ( "suche Select strBoerse" ) ;
95+ boerseSelect = page . getElementByName ( "strBoerse" ) ;
96+ Packages . de . willuhn . logging . Logger . debug ( "suche search-Button" ) ;
97+ searchButton = boerseSelect . getFirstByXPath ( "../../div/button" ) ;
98+
99+ input = page . getElementByName ( "dtDate1" ) ;
100+ input . setValue ( input . getMin ( ) ) ;
101+
102+ input = page . getElementByName ( "dtDate2" ) ;
103+ input . setValue ( input . getMax ( ) ) ;
104+ } catch ( error ) {
105+ // retrieve historic rates for "Zertifikate"
106+ Packages . de . willuhn . logging . Logger . debug ( "suche Select historic-prices-stock-market" ) ;
107+ boerseSelect = page . getElementById ( "historic-prices-stock-market" ) ;
108+ Packages . de . willuhn . logging . Logger . debug ( "suche search-Button" ) ;
109+ searchButton = page . getElementById ( "request-historic-price" ) ;
110+
111+ input = page . getElementById ( "derivative-historical-start-date" ) ;
112+ input . setValue ( DEFAULT_START_DATE ) ;
113+
114+ input = page . getElementById ( "derivative-historical-end-date" ) ;
115+ input . setValue ( input . getMax ( ) ) ;
78116 }
79- Packages . de . willuhn . logging . Logger . debug ( "suche Select strBoerse" ) ;
80- boerseSelect = page . getElementByName ( "strBoerse" ) ;
81- Packages . de . willuhn . logging . Logger . debug ( "suche search-Button" ) ;
82- searchButton = boerseSelect . getFirstByXPath ( "../../div/button" ) ;
83-
84- input = page . getElementByName ( "dtDate1" ) ;
85- input . setValue ( input . getMin ( ) ) ;
86-
87- input = page . getElementByName ( "dtDate2" ) ;
88- input . setValue ( input . getMax ( ) ) ;
89117 }
90118
91119 var liste = new ArrayList ( ) ;
92120 if ( ! page ) {
93121 Packages . de . willuhn . logging . Logger . error ( "Konnte Kurse Link nicht finden" ) ;
94122 } else {
95123 // Handelsplätze extrahieren
96-
124+
97125 var cfg = new Packages . jsq . config . Config ( "Handelsplatz" ) ;
98126 var listeHandelsplaetze = boerseSelect . getOptions ( ) ; // List of HtmlOption
99127 for ( var i = 0 ; i < listeHandelsplaetze . size ( ) ; i ++ ) {
100128 var platz = listeHandelsplaetze . get ( i ) ;
101129 cfg . addAuswahl ( platz . getText ( ) , platz . getValueAttribute ( ) ) ;
102130 }
103- liste . add ( cfg ) ;
131+ liste . add ( cfg ) ;
104132 }
105133
106134
@@ -138,8 +166,6 @@ function process(config) {
138166 } else {
139167 list = Packages . jsq . tools . HtmlUnitTools . analyse ( tab ) ;
140168 Packages . de . willuhn . logging . Logger . info ( list . size ( ) + " Kurse gefunden" ) ;
141-
142-
143169 for ( i = 0 ; i < list . size ( ) ; i ++ ) {
144170 try {
145171 hashmap = list . get ( i ) ;
@@ -195,4 +221,4 @@ function search(fetch, search) {
195221 page = wc . getPage (
196222 "http://www.finanzen.net/suchergebnis.asp?frmAktiensucheTextfeld=" + search
197223 ) ;
198- }
224+ }
0 commit comments