1
Use Htmlunit and when I give a Webclient.getPage() to a url, I get one Htmlpage thus (htmlPage.asXml()):
<?xml version="1.0" encoding="ISO-8859-1"?>
<html>
<head>
<script src="scripts/RelatorioGerencial_Resultados.js">
</script>
</head>
<body onload="dumpContent()">
ÿþ< s t y l e >
. f i l t r o
{
h e i g h t : 5 0 % ;
b o r d e r : 1 p x o u t s e t ;
f o n t - f a m i l y : a r i a l ;
f o n t - s i z e : 6 . 5 p t ;
o v e r f l o w - y : s c r o l l ;
b a c k g r o u n d - c o l o r : d 1 d 6 e 7 ;
}
. f i l t r o T e x t o I n p u t
{
f o n t - f a m i l y : a r i a l ;
f o n t - s i z e : 6 . 5 p t ;
b o r d e r : 1 p x s o l i d b l u e ;
}
< / s t y l e > < s c r i p t >
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
f u n c t i o n P o i n t ( i n X , i n Y )
{
t h i s . X = i n X ;
t h i s . Y = i n Y ;
}
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
f u n c t i o n g e t A b s o l u t e C o o r d i n a t e s ( o b j )
{
v a r r e t u r n X = 0 ;
v a r r e t u r n Y = 0 ;
v a r r e t u r n P o i n t ;
f o r ( ; o b j . o f f s e t P a r e n t ; o b j = o b j . o f f s e t P a r e n t )
{
r e t u r n X + = o b j . o f f s e t P a r e n t . o f f s e t L e f t ;
r e t u r n Y + = o b j . o f f s e t P a r e n t . o f f s e t T o p ;
}
r e t u r n P o i n t = n e w P o i n t ( r e t u r n X , r e t u r n Y ) ;
r e t u r n ( r e t u r n P o i n t ) ;
}
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
f u n c t i o n s t a r t U p ( s t r L a b e l )
{
v a r i S e n d e r D i v ;
v a r a r r O b j B a s e = p a r e n t . d o c u m e n t . g e t E l e m e n t s B y N a m e ( ' b a s e O b j ' ) ;
f o r ( i = 0 ; i < a r r O b j B a s e . l e n g t h ; i + + )
i f ( a r r O b j B a s e [ i ] . n a m e = = s t r L a b e l ) i S e n d e r D i v = a r r O b j B a s e [ i ] ;
v a r P = g e t A b s o l u t e C o o r d i n a t e s ( i S e n d e r D i v ) ;
p a r e n t . f i l t r o . n a m e = s t r L a b e l ;
p a r e n t . f i l t r o . i n n e r H T M L = r e t u r n V a l u e . i n n e r H T M L ;
p a r e n t . f i l t r o . s t y l e . t o p = P . Y + i S e n d e r D i v . o f f s e t H e i g h t ;
p a r e n t . f i l t r o . s t y l e . l e f t = P . X ;
p a r e n t . f i l t r o . s t y l e . v i s i b i l i t y = ' v i s i b l e ' ;
p a r e n t . f i l t r o . s t y l e . d i s p l a y = ' b l o c k ' ;
p a r e n t . g e t F i l t e r V a l u e ( s t r L a b e l ) ;
}
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
f u n c t i o n S e l e c t F i l t e r ( )
{
f i l t e r F i e l d . v a l u e = " " ;
v a r i n p u t F i l t e r s = d o c u m e n t . g e t E l e m e n t s B y N a m e ( ' f i l t e r I D ' ) ;
f o r ( K i n i n p u t F i l t e r s )
i f ( i n p u t F i l t e r s [ K ] . c h e c k e d = = t r u e ) f i l t e r F i e l d . v a l u e + = " ' " + i n p u t F i l t e r s [ K ] . v a l u e + " ' " ;
/ / a l e r t ( f i l t e r F i e l d . v a l u e ) ;
}
< / s c r i p t > < t e x t A r e a i d = " t x t Q u e r y " s t y l e = " w i d t h : 1 0 0 % ; h e i g h t : 1 0 0 % ; b o r d e r : 1 p x s o l i d r e d ; f o n t - f a m i l y : c o u r i e r n e w " o n D b l C l i c k = " t h i s . c r e a t e T e x t R a n g e ( ) . e x e c C o m m a n d ( ' S e l e c t A l l ' ) ; t h i s . c r e a t e T e x t R a n g e ( ) . e x e c C o m m a n d ( ' C o p y ' ) ; t h i s . c r e a t e T e x t R a n g e ( ) . e x e c C o m m a n d ( ' U n s e l e c t ' ) ; a l e r t ( ' Q u e r y C o p i a d a p a r a a Á r e a d e T r a n s f e r ê n c i a ' ) " > S e l e c t t o p ( 2 0 0 0 0 0 ) [ C A U S A ] . [ C D _ C A U S A ] A s [ C ó d . C a u s a ] ,
[ C A U S A ] . [ D T _ C A D A S T R A M E N T O ] A s [ D t . C a d a s t r a m e n t o ( R e g i s t r o ) ] ,
[ C O R P _ R E C U R S O _ H U M A N O _ R E S P _ C A U S A ] . [ I D _ L A P ] A s [ R e s p . C a d a s t r a m e n t o ( R e g i s t r o ) ] ,
[ C A U S A ] . [ S T _ C A U S A ] A s [ S t a t u s C a u s a ] ,
[ S E R V I C O _ A ] . [ C D _ A T E N D I M E N T O ] A s [ N º A ] ,
[ C O R P _ U F _ A ] . [ D S _ M U N I C I P I O ] A s [ M u n i c i p i o ] ,
[ C O R P _ U F _ A ] . [ C D _ U F ] A s [ U F ] ,
[ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ D T _ A N D A M E N T O ] A s [ D t . A n d a m e n t o ] ,
[ A N D A M E N T O _ A N D A M E N T O _ F A S E ] . [ D S _ F A S E _ A N D A M E N T O ] A s [ F a s e ]
F R O M [ C A U S A ]
L E F T O U T E R J O I N [ C O R P _ R E C U R S O _ H U M A N O ] [ C O R P _ R E C U R S O _ H U M A N O _ R E S P _ C A U S A ]
O N [ C A U S A ] . [ C D _ R E S P _ C A D A S T R A M E N T O ] = [ C O R P _ R E C U R S O _ H U M A N O _ R E S P _ C A U S A ] . [ C D _ R E C U R S O ]
L E F T O U T E R J O I N [ A T E N D I M E N T O ] [ S E R V I C O ]
O N [ C A U S A ] . [ C D _ C A U S A ] = [ S E R V I C O ] . [ C D _ C A U S A ]
L E F T O U T E R J O I N [ A T E N D I M E N T O ] [ S E R V I C O _ A ]
O N [ S E R V I C O ] . [ C D _ C A U S A ] = [ S E R V I C O _ A E J ] . [ C D _ C A U S A ]
A N D [ S E R V I C O ] . [ C D _ T I P O _ A T E N D I M E N T O ] = [ S E R V I C O _ A ] . [ C D _ T I P O _ A T E N D I M E N T O ]
A N D [ S E R V I C O ] . [ N U _ A T E N D I M E N T O ] = [ S E R V I C O _ A ] . [ N U _ A T E N D I M E N T O ]
A N D [ S E R V I C O _ A ] . [ C D _ T I P O _ A T E N D I M E N T O ] = ' A '
L E F T O U T E R J O I N [ D E N O M I N A C A O ] [ D E N O M I N A C A O _ A E J ]
O N [ S E R V I C O _ A ] . [ I D _ D E N O M I N A C A O ] = [ D E N O M I N A C A O _ A ] . [ I D _ D E N O M I N A C A O ]
I N N E R J O I N [ C O R P _ U F _ M U N I C I P I O ] [ C O R P _ U F _ A ]
O N [ D E N O M I N A C A O _ A ] . [ C D _ U F ] = [ C O R P _ U F _ A E J ] . [ C D _ U F ]
A N D [ D E N O M I N A C A O _ A E J ] . [ C D _ M U N I C I P I O ] = [ C O R P _ U F _ A E J ] . [ C D _ M U N I C I P I O ]
L E F T O U T E R J O I N [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ]
O N [ S E R V I C O ] . [ C D _ C A U S A ] = [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ C D _ C A U S A ]
A N D [ S E R V I C O ] . [ C D _ T I P O _ A T E N D I M E N T O ] = [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ C D _ T I P O _ A T E N D I M E N T O ]
A N D [ S E R V I C O ] . [ N U _ A T E N D I M E N T O ] = [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ N U _ A T E N D I M E N T O ]
L E F T O U T E R J O I N [ F A S E _ A N D A M E N T O ] [ A N D A M E N T O _ A N D A M E N T O _ F A S E ]
O N [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ I D _ F A S E _ A N D A M E N T O ] = [ A N D A M E N T O _ A N D A M E N T O _ F A S E ] . [ I D _ F A S E _ A N D A M E N T O ]
I N N E R J O I N [ V W _ R G E R _ V I S I B I L I D A D E _ C A U S A _ C O O R D E N A D O R ] [ V W _ R G E R _ V I S I B I L I D A D E _ C A U S A ]
O N [ C A U S A ] . [ C D _ C A U S A ] = [ V W _ R G E R _ V I S I B I L I D A D E _ C A U S A ] . [ C D _ C A U S A ]
A N D [ V W _ R G E R _ V I S I B I L I D A D E _ C A U S A ] . [ C D _ R E C U R S O ] = ' - 5 0 0 '
W H E R E [ C A U S A ] . [ C D _ O R I G E M ] = ' M '
A N D [ C A U S A ] . [ C D _ U N I D A D E ] = ' 1 0 3 '
A N D [ V W _ R G E R _ V I S I B I L I D A D E _ C A U S A ] . [ C D _ R E C U R S O ] = ' - 5 0 0 '
A N D [ S E R V I C O _ A ] . [ C D _ T I P O _ A T E N D I M E N T O ] = ' A '
A N D [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ C D _ C A U S A ] I S N O T N U L L
A N D [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ C D _ T I P O _ A T E N D I M E N T O ] I S N O T N U L L
A N D [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ N U _ A T E N D I M E N T O ] I S N O T N U L L
A N D [ V W _ R G E R _ A N D A M E N T O _ A N D A M E N T O ] . [ C D _ A N D A M E N T O ] I S N O T N U L L
A N D [ A N D A M E N T O _ A N D A M E N T O _ F A S E ] . [ D S _ F A S E _ A N D A M E N T O ] I N ( ' G D O C ' ) < / t e x t A r e a > < b o d y >
< d i v s t y l e = " d i s p l a y : n o n e " >
< t a b l e >
< t r >
< t d >
< d i v i d = " c o n t r o l e L o t e " > < i n p u t t y p e = " h i d d e n " i d = " x m l L o t e " n a m e = " x m l L o t e " v a l u e = " " > < b u t t o n v a l u e = " " n a m e = " l o a d L o t e " i d = " l o a d L o t e " s t y l e = " f o n t - f a m i l y : v e r d a n a ; f o n t - s i z e : 7 p t ; c u r s o r : p o i n t e r ; " o n c l i c k = " l o a d L o t e ( x m l L o t e ) " > < i m g s r c = " i m a g e s / u p l o a d _ l o t e . g i f " a l i g n = " a b s M i d d l e " > C a r r e g a r L o t e ( < s p a n i d = " t a m L o t e " s t y l e = " b o r d e r : 0 p x " n a m e = " t a m L o t e " > 0 < / s p a n > ) < / b u t t o n > < b u t t o n v a l u e = " " n a m e = " c l e a r L o t e " i d = " c l e a r L o t e " s t y l e = " f o n t - f a m i l y : v e r d a n a ; f o n t - s i z e : 7 p t ; c u r s o r : p o i n t e r ; " o n c l i c k = " c l e a r L o t e ( ) " > < i m g s r c = " / i m a g e s / l i m p a r . g i f " a l i g n = " a b s M i d d l e " s t y l e = " v e r t i c a l - a l i g n : m i d d l e " > L i m p a r L o t e < / b u t t o n > < / d i v >
< / t d >
< t d >
< D I V I D = " P a g i n g C o n t r o l " > < i n p u t i d = " f i s t P a g e " t y p e = " b u t t o n " s t y l e = " c u r s o r : h a n d ; b o r d e r : 1 p x s o l i d # 9 9 C ; " o n C l i c k = " g o F i r s t P a g e ( ) " v a l u e = " | < " > < i n p u t i d = " p r e v i o u w P a g e " t y p e = " b u t t o n " s t y l e = " c u r s o r : h a n d ; b o r d e r : 1 p x s o l i d # 9 9 C " o n C l i c k = " g o P r e v i o u s P a g e ( ) " v a l u e = " < " d i s a b l e d = " t r u e " > < i n p u t i d = " c u r r e n t P a g e " d i s a b l e d = " t r u e " s t y l e = " b o r d e r : 1 p x i n s e t ; w i d t h : 1 p x ; m a r g i n : 0 p x 0 p x 1 p x 0 p x ; o v e r f l o w : v i s i b l e " v a l u e = " 1 / 1 " > < i n p u t i d = " f i s t P a g e " t y p e = " b u t t o n " s t y l e = " c u r s o r : h a n d ; b o r d e r : 1 p x s o l i d # 9 9 C " o n C l i c k = " g o N e x t P a g e ( ) " v a l u e = " > " d i s a b l e d = " t r u e " > < i n p u t i d = " p r e v i o u w P a g e " t y p e = " b u t t o n " s t y l e = " c u r s o r : h a n d ; b o r d e r : 1 p x s o l i d # 9 9 C " o n C l i c k = " g o L a s t P a g e ( ) " v a l u e = " > | " > < / D I V >
< / t d >
< / t r >
< / t a b l e >
< T A B L E b o r d e r = " 1 " w i d t h = " 1 0 0 % " >
< T B O D Y I D = " R e s u l t S e t " >
< T R >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 2 . 1 8 8 1 8 3 8 0 7 4 3 9 8 2 4 7 % " a l i g n = " l e f t " n o w r a p = " 1 " > < i n p u t t y p e = " c h e c k b o x " n a m e = " l o t e " i d = " l o t e " o n c l i c k = " c h e c k M e ( t h i s ) " v a l u e = " T R I 0 0 5 0 3 0 4 " > < A h r e f = " / P a g i n a s / P r o n t u a r i o _ J u r i d i c o / G e r e n c i a _ A t e n d i m e n t o / L o t e / c a r r e g a r C a u s a . a s p ? c d _ C a u s a = T R I 0 0 5 0 3 0 4 " > T P I 0 0 7 0 3 0 4 < / A > < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 3 . 5 0 1 0 9 4 0 9 1 9 0 3 7 2 % " a l i g n = " c e n t e r " n o w r a p = " 1 " > 1 9 / 0 8 / 2 0 1 9 < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 5 . 2 5 1 6 4 1 1 3 7 8 5 5 5 8 % " a l i g n = " l e f t " n o w r a p = " 1 " > s c o r . p m e d e i r o s < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 1 . 9 6 9 3 6 5 4 2 6 6 9 5 8 4 2 4 % " a l i g n = " l e f t " n o w r a p = " 1 " > E M C U R S O < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 5 . 4 7 0 4 5 9 5 1 8 5 9 9 5 6 2 % " a l i g n = " l e f t " n o w r a p = " 1 " > 0 1 0 0 1 3 3 6 0 1 9 2 5 < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 5 5 . 7 9 8 6 8 7 0 8 9 7 1 5 5 3 6 % " a l i g n = " l e f t " n o w r a p = " 1 " > U B E R A B A < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 0 . 4 3 7 6 3 6 7 6 1 4 8 7 9 6 5 % " a l i g n = " l e f t " n o w r a p = " 1 " > M G < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 3 . 5 0 1 0 9 4 0 9 1 9 0 3 7 2 % " a l i g n = " c e n t e r " n o w r a p = " 1 " > 1 9 / 0 8 / 2 0 1 0 < / T D >
< T D s t y l e = " b o r d e r : 1 p x s o l i d l i g h t g r e y ; b o r d e r - r i g h t : 1 p x s o l i d d a r k g r e y ; p a d d i n g : 0 p x 1 0 p x 0 p x 1 0 p x " c l a s s = " R e s u l t C e l l " w i d t h = " 2 1 . 8 8 2 8 3 8 0 7 7 3 9 8 2 5 % " a l i g n = " l e f t " n o w r a p = " 1 " > G D O C < / T D >
< / T R >
< / T B O D Y >
< / T A B L E >
< D I V I D = " T o t a l " > R e g i s t r o L o c a l i z a d o : < s t r o n g > 1 < / s t r o n g > < / D I V >
< / d i v >
< / b o d y >
<script type="text/javascript">
//<![CDATA[
try{
parent.document.getElementById('waitMessage').style.display = 'none';
parent.$('.botoes').show('slow');
}
catch(e){
}
//]]>
</script>
</body>
</html>
Requisition code:
WebRequest webRequest = WebClientFactory.getWebRequest("https://siteConfidencial/RelatorioGerencial_Resultado.asp", HttpMethod.POST);
final List<NameValuePair> params = new ArrayList<>();
String entidade = Util.getEncoded("<Atributos><pagina>0</pagina><lote></lote></Atributos>");
String atributo = Util.getEncoded("atributosTeste");
params.add(new NameValuePair("Entidade", entidade));
params.add(new NameValuePair("Atributo", atributo));
params.add(new NameValuePair("label", ""));
params.add(new NameValuePair("xmlLote", ""));
params.add(new NameValuePair("filtroResumo", ""));
webRequest.setRequestBody(params.stream().map(NameValuePair::toString).collect(Collectors.joining("&")));
HtmlPage finalPage = WebClientFactory.getPage(webRequest);
Settings for the Webclient:
public static synchronized WebClient getInstance() {
if (WebClientFactory.THREAD_LOCAL_WEB_CLIENT.get() == null) {
webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setAlertHandler(new CollectingAlertHandler());
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setGeolocationEnabled(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setTimeout(DEFAULT_REQUEST_TIMEOUT);
webClient.addRequestHeader("Accept-Language", "pt-BR");
webClient.getCache().setMaxSize(0);
WebClientFactory.THREAD_LOCAL_WEB_CLIENT.set(webClient);
}
return WebClientFactory.THREAD_LOCAL_WEB_CLIENT.get();
}
I needed to access the tds (use xpath) but I can’t. What would be better to do?
Included Webclient request and settings
– laaf