From: Davi M. C. <dav...@gm...> - 2016-07-10 11:09:04
|
Hello, I made some changes in my code, leaving it more complete. Still, it does not work, my code enters an infinite loop in print "Waiting for symbol tag ...". That is, I can not insert a symbol from my code, though I can do it in the browser. BrowserVersion browserVersion = BrowserVersion.FIREFOX_45; WebClient webClient = new WebClient(browserVersion); webClient.setAjaxController(new SyncAjaxController()); webClient.setCookieManager(new CookieManager()); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setCssEnabled(true); webClient.getOptions().setUseInsecureSSL(true); try { System.out.println("Acessing webpage..."); HtmlPage page; page = webClient.getPage( " https://dwq4do82y8xi7.cloudfront.net/bovespa/widgetembed/?symbol=IBOV&interval=1&hidesidetoolbar=0&symboledit=1&toolbarbg=f1f3f6&editablewatchlist=1&details=1&studies=&widgetbarwidth=300&hideideas=1&theme=White&style=3&timezone=exchange&withdateranges=1&studies_overrides=%7B%7D&overrides=%7B%7D&enabled_features=%5B%5D&disabled_features=%5B%5D&locale=pt&utmsource=www.bmfbovespa.com.br&utmmedium=www.bmfbovespa.com.br/pt_br/servicos/market-data/cotacoes/ "); List<Node> nodesAdicionarSimbolo = null; while (nodesAdicionarSimbolo == null || (nodesAdicionarSimbolo != null && nodesAdicionarSimbolo.size() == 0)) { nodesAdicionarSimbolo = (List<Node>) page.getByXPath("//input[@placeholder='Adicionar Símbolo']"); System.out.println("Looking for 'Adicionar Símbolo'..."); } System.out.println("'Adicionar Símbolo' found!"); { String symbol = "BBAS3"; HtmlTextInput inputAdicionarSimbolo = (HtmlTextInput) nodesAdicionarSimbolo.get(0); System.out.println("Putting symbol in 'Adicionar Símbolo'..."); inputAdicionarSimbolo.setTextContent(symbol); { HtmlElement input = (HtmlElement) inputAdicionarSimbolo; input.focus(); input.type(symbol); System.out.println("Pressing the Enter key..."); page = (HtmlPage) input.type('\n'); } } { List<Node> nodesCotacaoDiaria; do { nodesCotacaoDiaria = (List<Node>) page.getByXPath("//div[@class='symbol']"); System.out.println("Waiting for symbol tag..."); } while (nodesCotacaoDiaria == null || (nodesCotacaoDiaria != null && nodesCotacaoDiaria.size() == 0)); System.out.println("Symbol tag found!"); } } catch (Exception e) { e.printStackTrace(); } webClient.close(); On Sat, Jul 9, 2016 at 12:02 AM, Davi Medeiros Cabral <dav...@gm... > wrote: > Hello, > > I'm doing a system which need to fill some fields the following website: > > > https://dwq4do82y8xi7.cloudfront.net/bovespa/widgetembed/?symbol=IBOV&interval=1&hidesidetoolbar=0&symboledit=1&toolbarbg=f1f3f6&editablewatchlist=1&details=1&studies=&widgetbarwidth=300&hideideas=1&theme=White&style=3&timezone=exchange&withdateranges=1&studies_overrides=%7B%7D&overrides=%7B%7D&enabled_features=%5B%5D&disabled_features=%5B%5D&locale=pt&utmsource=www.bmfbovespa.com.br&utmmedium=www.bmfbovespa.com.br/pt_br/servicos/market-data/cotacoes/ > > To be more precise, I am trying to insert a symbol in the list of symbols > that site, using, for this, the input field "Adicionar Símbolo". > > <input class="wl-symbol-edit" placeholder="Adicionar Símbolo" > maxlength="1000" style="text-transform: none; font-weight: normal;" > autocomplete="off" type="text"> > > Therefore, I wrote the following code: > > BrowserVersion browserVersion = BrowserVersion.INTERNET_EXPLORER_11; > webClient = new WebClient(browserVersion); > webClient.getOptions().setCssEnabled(true); > webClient.setSyncAjaxMode(new SyncAjaxController()); > webClient.getOptions().setJavaScriptEnabled(true); HtmlPage page = > webClient.getPage(url); List<Node> nodesAdicionarSimbolo = (List<Node>) > page.getByXPath("//input[@placeholder='Adicionar Símbolo']"); if > (nodesAdicionarSimbolo != null && nodesAdicionarSimbolo.size() > 0) { > HtmlTextInput inputAdicionarSimbolo = (HtmlTextInput) nodesAdicionarSimbolo. > get(0); HtmlElement input = (HtmlElement) inputAdicionarSimbolo; > input.focus(); input.type("BBAS3\n"); System.out.println(page.asXml()); } > > However, the println does not return the below structure, as in the > website. > > <div class="symbol"><span class="name">BBAS3</span>... > > What am I doing wrong? > |